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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 21, 2011, 1:13 AM EDT
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/
TulasiRank #2,544 · 549 reputationPosted Oct 20, 2011, 8:22 PM EDT
Lucy Jane37 reputationPosted Oct 20, 2011, 9:32 PM EDT
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.
Priya LingeRank #785 · 2.9K reputationPosted Oct 20, 2011, 11:02 PM EDT
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.
Vipul KelkarRank #1,061 · 1.8K reputationPosted Oct 21, 2011, 12:58 AM EDT
what version of .net framework are u using ?
VulpesRank #55 · 29.2K reputationPosted Oct 21, 2011, 1:00 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 2, 2012, 10:03 PM EST
"var" key word only support if your targer framework is 3.0 or above.
hope this help.