I keep reading, in many forums, people’s comments complaining about the code posted, the VB developers complain that it is difficult to read C# code and vice verse.
The two languages are almost identical. C# is case sensitive whereas VB is not.
If you come from a C++, Java or Delphi background it is easier to work with C#. If you come from VB6 it is easier to work with VB.NET.
A good VB and C# language comparison can be found here.
A very good summary of common programming concepts with side-by-side code examples or tables can be found:
- For Keywords Compared in Different Languages here
- For Languages Data Types here
- For Languages Operators here
- For Controls and Programmable Objects here
Some programming language references:
Java and C# have many similarities. These are two very useful links
The C# Programming Language for Java Developers
The Java™ Language Specification
C# is empowered with Generics. This is a nice feature of the language. With Generics you can enforce compiler-time type safety. This way you can minimize wrong data type assignments.
With Generics it is possible to declare Generic methods or even Generic classes.
You can write fewer lines of code if you choose to use a Generic method instead of overloaded methods. The following example demonstrates the concept:
1: using System;
2: using System.Collections.Generic;
3:
4:
5: namespace Example {
6: class Program {
7: static void Main(string[] args) {
8: //Create arrays of different types
9: int[] intArray={1,2,3,4,5,6,7,8};
10: double[] doubleArray ={ 1.0, 2.1, 3.2, 4.3, 5.4, 6.5 };
11: char[] charArray ={ 'E', 'X', 'A', 'M', 'P', 'L', 'E' };
12: string[] stringArray ={ "Hello", "World", "Example" };
13:
14: //Using the generic DisplayArray for different array types
15: Console.WriteLine("intArray");
16: DisplayArray(intArray);
17: Console.WriteLine("doubleArray");
18: DisplayArray(doubleArray);
19: Console.WriteLine("charArray");
20: DisplayArray(charArray);
21: Console.WriteLine("stringArray");
22: DisplayArray(stringArray);
23: Console.Write("Press <Enter> ");
24: Console.ReadLine();
25:
26: } // end Main
27: //T is the generic Type. A type parameter list delimited by <>
28: //The declaration below save us from the need to declare different overloaded methods
29: static void DisplayArray<T>(T[] displayArray) {
30: foreach (T element in displayArray) {
31: Console.Write(element + " ");
32: }
33: Console.WriteLine();
34: }
35: }
36: }
No Responses to “.NET programming languages”