This blog is subject the DISCLAIMER below.

Wednesday, February 14, 2007

What's new in C# 3.0 ? Part 4

in this post i will speak about 3 small things:-
1: - Object initializers.
2: - Query expression.
3:- implicitly typed arrays.

1: - Object initializers :-
Now i can initialize any public property in object construction, so there is no need to write multiple
constructors like this eg ..

point p = new point { x = 5 , y = 9 } ;
button btn = new button { Text = "username" , Width = 20 , Height = 5 } ;
and so on .. where Text,Widht and Height are Public properties in the Button Class.


2: - Query expression :-
i will explain it directly in a small example : -

from c in students
where c.Name == "BillGates"
select c.address.
now this became apart of C# syntax now we can get a compilation error if i wrote wrong
statement ( in the previous versions of C# we were writing it between " ".
the query expression not just for sql statements but also i can use it in my arrays or any structure i made in my code.
( really this is great ) .

3 : - implicitly typed arrays :-
it is same as implicitly typed variable the type of the array is inferred from the initialization value like this :-
var a = new [] { 1, 2, 3 } ; //array of intergers.
var b = new [] { "hi","man"}; // array of srings.
var c = new [] { 1, 2, "kkk"}; // Compilation error.

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

1 comment:

Ahmed Essawy said...

Query expression :D .
2al Java 2al .