FCI-Helwan blog

Just another FCI-H weblog

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

Advertisements

February 14, 2007 - Posted by | C#

1 Comment »

  1. Query expression 😀 .
    2al Java 2al .

    Comment by Ahmed Essawy | February 16, 2007 | Reply


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: