FCI-Helwan blog

Just another FCI-H weblog

What’s new in C# 3.0 ? Part 3

assume you want to make a fly variable(which i will use it once in my code) of complex type, all what i have to do is go to the solution explorer and add a new class for this type, by this way if i want to make 10 new types i will make 10 different class, but this is not the best solution so C# 3.0 came with the the best solution with the Anonymous Type.

now i don’t have to write a class foreach type i wanna use, the compiler will do this for my 🙂
eg .. i want to make a new type which will hold my firstname , lastname and my age
it will be like this :-
var UserData = new {Fisrtname = “Mohamed”, LastName = “Gamal” , age = 19 };

in the compilation time the compiler will generate a temp class for this type , the Members of this class is a Read\Write properties which inferred from the Object initializer (i will speak about it in another post isA ).
back to our example .. here the compiler will make 3 properties in this class, 2 of type string and the third of type int, the compiler can do this job during the compilation time depending on the initialization value.

by this way i don’t have to generate classes for fly variables and this increases the code readability and save many lines of code to be written.

That’s it.
See you in the Next Part isA


February 13, 2007 - Posted by | C#

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: