Evolution of C# Development from C# 1 to C# 4
Hi,
Today i started studying the book Jon Skeet's C# in Depth in which Jon Skeet explained all the key difference in how C# 1 was and how it has improved by evolving to c# 4 it is a very nice book and i would recommend every c# developer to read it once.
I came to know how c# 1 has evolved from beginning to now, and c# added features to ease the developers and make their life easier and easier.
So i will be sharing that how c# evolved from c# 1 to c# 4 and from a simply class i will tell the differences that came and how it's enhanced version by version to be more easy for developers.
First we will create a class of User that how it would be implemented in the C# 1:
The above c# 1 code, and it is not any rocket science, all things are straight forward, we have created a class User with properties FirstName,LastName and Gender and created a static method which is returning hardcoded four users in ArrayList.
Today i started studying the book Jon Skeet's C# in Depth in which Jon Skeet explained all the key difference in how C# 1 was and how it has improved by evolving to c# 4 it is a very nice book and i would recommend every c# developer to read it once.
I came to know how c# 1 has evolved from beginning to now, and c# added features to ease the developers and make their life easier and easier.
So i will be sharing that how c# evolved from c# 1 to c# 4 and from a simply class i will tell the differences that came and how it's enhanced version by version to be more easy for developers.
C# 1:
First we will create a class of User that how it would be implemented in the C# 1:
public class User { private string firstName; public string FirstName { get { return firstName; } } private string lastName; public string LastName { get { return lastName; } } private string gender; public string Gender { get { return gender; } } public User(string firstName, string lastName, string gender) { this.firstName = firstName; this.lastName = lastName; this.gender = gender; } public static ArrayList GetAllUsers() { ArrayList Users= new ArrayList(); Users.Add(new User("Leo", "Messi", "Male")); Users.Add(new User("Maria", "Sharapova", "Female")); Users.Add(new User("Imran", "Khan", "Male")); Users.Add(new User("Christiano", "Ronaldo", "Male")); return Users; } public override string ToString() { return string.Format("{0}: {1} : {2}", firstName, lastName,gender); } }
The above c# 1 code, and it is not any rocket science, all things are straight forward, we have created a class User with properties FirstName,LastName and Gender and created a static method which is returning hardcoded four users in ArrayList.
LIMITATIONS OF C# 1:
According to book, there are three limitations in the above C# 1 code:
1) Array List has no compile-time information that what is exactly. If we try to put some other type of object in it, it will not give any compile time error, but on run-time it will surely bang the program flow.
2)We have provided public getters in the above code which means that if we want it setters also added that they had have to be public as well.
3)There is alot of fluff invloved in creating the properties and variables, which results in complicated code for a single task to encapsulate three string properties of the class.