how to use VAR keyword in ASP.net 2.0

Posted by Alok under ASP.NET on 4/5/2011 | Points: 10 | Views : 3351 | Status : [Member] | Replies : 3
i have a application in .net3.5 which use VAR keyword .i want to use this application in 2.0 ,but it does not read var keyword
how can i use VAR keyword in .net 2.0.????

Thanks & Regards,
Alokssm



Responses

Posted by: Sashys on: 4/19/2011 [Member] Starter | Points: 25

Up
0
Down
The keyword VAR is introduces in C# 3.0 which we don't have in older versions of C#. It Declares Implicitly typed variable where the compiler identifies the type automatically. We need to use / declare the Explicit type variable based on our values. The object type will help us in this regard for some extent. Please paste the code snippet of your issue if possible. We can try for exact alternative for the problem.

Sasikumar .M

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manishsoni on: 4/20/2011 [Member] Starter | Points: 25

Up
0
Down
Dear Alok,


var in anonymous type. It is introduced in framework 3.0

in This type variable you can assign any type of value like string, int, float even objects too.

Anonymous types are particularly useful when querying and transforming/projecting/shaping data with LINQ.

Example :--
var i=5;
var a="Abcd efg";
var b= 5.5555;
var b=new class();

you can use in LINQ also;

like
var abc= from (b in Table_123 where id=1 select b).List();

so if you want to degrade your application version. explicitly declare variable for such .

Thanks


Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manishsoni on: 4/20/2011 [Member] Starter | Points: 25

Up
0
Down
Dear Alok,


var in anonymous type. It is introduced in framework 3.0

in This type variable you can assign any type of value like string, int, float even objects too.

Anonymous types are particularly useful when querying and transforming/projecting/shaping data with LINQ.

Example :--
var i=5;
var a="Abcd efg";
var b= 5.5555;
var b=new class();

you can use in LINQ also;

like
var abc= from (b in Table_123 where id=1 select b).List();

so if you want to degrade your application version. explicitly declare variable for such .

Thanks


Alok, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response