how to run the linq program in ordinary console application

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 56
Reputation: karthi_selva is an unknown quantity at this point 
Solved Threads: 0
karthi_selva karthi_selva is offline Offline
Junior Poster in Training

how to run the linq program in ordinary console application

 
0
  #1
Feb 6th, 2009
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....
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

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

 
0
  #2
Feb 6th, 2009
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
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
1
  #3
Feb 6th, 2009
var is a C# 3.0 feature; it can't possibly work with a C# 2 compiler.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

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

 
0
  #4
Feb 6th, 2009
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...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
3
  #5
Feb 6th, 2009
It doesn't help that his code won't work in C# 3.0 either. ev is not in scope where he uses it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

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

 
0
  #6
Feb 6th, 2009
Yes because he doesn't write this code within method!! but I was replying in language syntax perspective...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 56
Reputation: karthi_selva is an unknown quantity at this point 
Solved Threads: 0
karthi_selva karthi_selva is offline Offline
Junior Poster in Training

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

 
0
  #7
Feb 7th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
1
  #8
Feb 7th, 2009
So don't use var, use the type name.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

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

 
0
  #9
Feb 7th, 2009
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.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum


Views: 1005 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC