943,749 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2289
  • C# RSS
Feb 6th, 2009
0

how to run the linq program in ordinary console application

Expand Post »
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....
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
karthi_selva is offline Offline
65 posts
since Oct 2008
Feb 6th, 2009
0

Re: how to run the linq program in ordinary console application

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
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Feb 6th, 2009
1

Re: how to run the linq program in ordinary console application

var is a C# 3.0 feature; it can't possibly work with a C# 2 compiler.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Feb 6th, 2009
0

Re: how to run the linq program in ordinary console application

Quote ...
Quote ...
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...
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Feb 6th, 2009
3

Re: how to run the linq program in ordinary console application

It doesn't help that his code won't work in C# 3.0 either. ev is not in scope where he uses it.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Feb 6th, 2009
0

Re: how to run the linq program in ordinary console application

Yes because he doesn't write this code within method!! but I was replying in language syntax perspective...
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Feb 7th, 2009
0

Re: how to run the linq program in ordinary console application

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
karthi_selva is offline Offline
65 posts
since Oct 2008
Feb 7th, 2009
1

Re: how to run the linq program in ordinary console application

So don't use var, use the type name.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Feb 7th, 2009
0

Re: how to run the linq program in ordinary console application

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.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Capture your screen in a bitmap.
Next Thread in C# Forum Timeline: The 2000 first primes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC