How to compile with collections from command line?

S

Siegfried Heintze

The program below works when compiling it with VS2008. However, when I try to
compile it from the command line I get this error:


props.cs(38,53): error CS0246: The type or namespace name 'List' could not
be found (are you missing a using directive or an assembly reference?)
props.cs(38,66): error CS1925: Cannot initialize object of type
'List<Person>' with a collection initializer

I was hoping I could go to online help and find the dll I need to reference
but no luck!

How do I determine the DLL for a given package? What would be the command to
compile this from the command line?

Incidently, do I need to buy VS2008 to compile simple programs like this or
is the compiler included in the .NET framework that I can download for free?

Thanks,
Siegfried

/**
* Begin commands to execute this file using MS.NET with CMD.EXE
* csc /out:props.exe /checked /d:noprompt /debug props.cs
* props
* del props.exe
* del props.pdb
* End commands to execute this file using MS.NET with CMD.EXE
*/

using System;
using System.Runtime.InteropServices;
class Person {
public Person() { }
public string name { get; set; }
}
class Parent : Person {
public System.Collections.Generic.List<Person> children;
}
public class props {
[DllImport("msvcrt.dll", SetLastError = true)]
static extern int _getch();
static System.IO.TextWriter outp = System.Console.Out;
static System.IO.TextReader inp = System.Console.In;
public static void Main(string[] args){
try{
Person p = new Person { name = "sieglinde" };
outp.WriteLine(p.name);
Parent siegfried = new Parent { children= new List<Person> { new
Person{name="sieglinde"} }, name="siegfried"};
} finally {
#if noprompt
outp.WriteLine("terminating props.cs");
#else
outp.Write("Enter any key to exit props.cs: ");
_getch();
#endif
}
}
}
 
J

Jon Skeet [C# MVP]

Siegfried Heintze said:
The program below works when compiling it with VS2008. However, when I try to
compile it from the command line I get this error:

props.cs(38,53): error CS0246: The type or namespace name 'List' could not
be found (are you missing a using directive or an assembly reference?)
props.cs(38,66): error CS1925: Cannot initialize object of type
'List<Person>' with a collection initializer

I was hoping I could go to online help and find the dll I need to reference
but no luck!

You're missing a using directive:

using System.Collections.Generic;


I suspect you'll find that it doesn't actually build in VS2008 either,
if you make sure that you really have only got the code you provided.
Incidently, do I need to buy VS2008 to compile simple programs like this or
is the compiler included in the .NET framework that I can download for free?

The compiler is in the framework (as is MSBuild).
 
S

Siegfried Heintze

I already have SQL Server as part of VS2005 standard edition.

I think I would like to download the DVD with everything (C#, VB and ASP).
Will the new SQL Server 2005 on the DVD clobber my old SQL Server 2005? Is
the SQL Server 2005 I get for free less capable than the one I paid for as
part of VS2005?


Thanks,
Siegfried
 
M

Marc Gravell

Will the new SQL Server 2005 on the DVD clobber my old SQL Server 2005
The one on he DVD is "express"; a reduced (but still very functional)
version. but if you already have "proper" SQL Server 2005, then simply
don't install this bit... it isn't an "all or nothing" deal... you can
pick and choose.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top