Namespace to implement LINQ
I created a program to implement LINQ and i am using var keyword for object Initializers, but the var keyword is not supporting, Can anyone tell me which namespace should i include to implement Type refrencing with LINQ.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prabhu RajaPosted Oct 21, 2011, 5:13 AM
using System;
using System.Linq;
public sealed class Program
{
static double Square(double n)
{
Console.WriteLine("Computing Square(" + n + ")...");
return Math.Pow(n, 2);
}
public static void Main()
{
int[] numbers = { 1, 2, 3 };
var query =
from n in numbers
select Square(n);
foreach (var n in query)
Console.WriteLine(n);
}
}
OUTPUT:
Computing Square(1)...1
Computing Square(2)...
4
Computing Square(3)...
9
And you may try the following Articles :
Syntaxes and Clauses in LINQ;
http://www.c-sharpcorner.com/UploadFile/ravi_panara/4520/
Understanding LINQ:
http://www.c-sharpcorner.com/UploadFile/logisimo/2256/
Jignesh TrivediPosted Jan 3, 2012, 3:03 AM
"var" key word only support if your targer framework is 3.0 or above.
hope this help.
VulpesPosted Oct 21, 2011, 5:00 AM
Vipul KelkarPosted Oct 21, 2011, 4:58 AM
what version of .net framework are u using ?
Priya LingePosted Oct 21, 2011, 3:02 AM
Please see below link.
http://www.dotnetperls.com/var
Namespace : using System.Linq;
public Form2()
{
InitializeComponent();
var v = new student { Name = "Sheena", Roll_no = 10 };
}
public class student
{
public string Name { get; set; }
public int Roll_no { get; set; }
}
Hope this will help you.
Thanks.
Lucy JanePosted Oct 21, 2011, 1:32 AM
public class student
{
public string Name { get; set; }
public int Roll_no { get; set; }
var v = new student { Name = "shweta", Roll_no = 10 };
}
Here var keyword is not Identifiable.
TulasiPosted Oct 21, 2011, 12:22 AM