Archives for the 'C#' Category
C# Hidden Danger #1: The const Keyword
Declaring a constant with the const keyword makes it a compile-time constant. In the generated IL, all references to a compile-time constant will be replaced by its actual value. Now suppose that a compile-time constant is declared in one assembly and referenced in other assemblies. If the definition of the constant ever needs to be […]
My Take on Visual Studio 2008
I just finished five days of Visual Studio 2005 (.NET 2.0) training, with a day of Visual Studio 2008 (.NET 3.5) sprinkled on. My take on VS2008 are as follows:
First, AJAX integration is very tight. I have actually done AJAX the manual way before (with PHP) and I appreciate how much coding VS has […]
Difference Between C# and VB
This is a beautiful interview trivia question: What is the major difference between C# and VB?
Answer: In C# you can write “unsafe” code, i.e., code involving pointers, whereas in VB you cannot.
Update 20 February 2008
Also, VB does not have anonymous methods.
Coding against the DB
If you have to embed SQL in your code, this is how to do it in C#.
Highlights:
the using statement, which is like try-finally
@-quoted string literals
Parameters.AddWithValue(parameterName, value) (new in .NET Framework 2.0)
Coming from an ASP/PHP-MySQL background, it’s great to not have to escape special SQL characters or to enclose varchar values within single quotes.
using System.Data;
using System.Data.SqlClient;
using […]
Polymorphism Explained
Polymorphism is the ability of an object to represent more than one type.
The MSDN Library explains polymorphism quite well. Emphasis mine.
PLAIN TEXT
C#:
public class A
{
// code
}
public class B : A
{
// code
}
"In the example above, class B is effectively both B and A. When you access a B object, you can use [...]
