how to run the linq program in ordinary console application
hi,
i am doing the project in .net. i m using linq in my project
i using vs2005 and installed the linq.
i am able to run the linq only in LinqconsoleApplication. but i need to run in normal console application.
ie i like to create one class file and do some linq operations. but in normal class or console application, i m not able to r u the linq operations
i m using the following headers....
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.DLinq;
using System.Data.Linq;
using System.Query;
using System.Reflection;
using System.Expressions;
using System.Query.Script;
class pr
{
var x =new int[] {1,2,3,4,5,6,7,8};
var ev=from a in x
where (ev %2)==0
select a;
foreach(var i in ev)
console.writeline(i);
}
after compile this code
i got the type or namespace var can't find out..
if u know the solution for the above one. please share ur ideas....
karthi_selva
Junior Poster in Training
65 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
1. Please use whole words.
2. Please post the proper error text
3. What line is the err on
4. A console app is a console app, the only difference will be that it has linq already in the references and uses clause you should be able to just run it from a command line
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
var is a C# 3.0 feature; it can't possibly work with a C# 2 compiler.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
var is a C# 3.0 feature; it can't possibly work with a C# 2 compiler.
i using vs2005 and installed the linq.
I think he should select from LINQ project-> Console LINQ project not console application directly...
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
It doesn't help that his code won't work in C# 3.0 either. ev is not in scope where he uses it.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
Yes because he doesn't write this code within method!! :) but I was replying in language syntax perspective...
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.DLinq;
using System.Data.Linq;
using System.Query;
using System.Reflection;
using System.Expressions;
using System.Query.Script;
namespace consoleapplication1
{
class Program
{
static void main()
{
var num =new int[] {1,2,3,4,5,6,7,8,9};
var evennumbers= from n in num
where (n %2) ==0
select n;
foreach(var x in evennumbers)
console.writeline(x);
}
}
}
I wrote this code in ordinary console application in VS2005.
i compiled this code, after compilation i got the following errors
"Error 1 The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?) "
// Error 2 is above one
Error 3 foreach statement cannot operate on variables of type 'var' because 'var' does not contain a public definition for 'GetEnumerator'
//Error 4= Error 1
Error 5 The best overloaded method match for 'System.Console.WriteLine(bool)' has some invalid arguments
These are arise during compile time.
but one think the same code is executed in Previewconsole application in VS2005.
but i need it to run normal ConsoleApplication in VS2005.
i my organization have not VS2008. so i must work in VS2005.
karthi_selva
Junior Poster in Training
65 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
So don't use var, use the type name.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
Create project from LINQ Console Application not Console Application
You'll find some project with prefix "LINQ" added to project types in VS2005 after installing LINQ SDK.
If you can send us snapshot of your VS installed project templates please do.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276