Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: Avoid contextmenustrip pop-up Pin
cocoonwls13-May-08 17:38
cocoonwls13-May-08 17:38 
GeneralRe: Avoid contextmenustrip pop-up Pin
baranils13-May-08 19:05
baranils13-May-08 19:05 
GeneralRe: Avoid contextmenustrip pop-up Pin
cocoonwls13-May-08 22:50
cocoonwls13-May-08 22:50 
GeneralRe: Avoid contextmenustrip pop-up Pin
baranils13-May-08 23:01
baranils13-May-08 23:01 
GeneralRe: Avoid contextmenustrip pop-up Pin
cocoonwls14-May-08 15:09
cocoonwls14-May-08 15:09 
GeneralRe: Avoid contextmenustrip pop-up Pin
baranils14-May-08 18:59
baranils14-May-08 18:59 
GeneralRe: Avoid contextmenustrip pop-up Pin
cocoonwls14-May-08 22:14
cocoonwls14-May-08 22:14 
QuestionProblem with C# 3.0 Collection and Object Initializers [modified] Pin
User 665813-May-08 7:58
User 665813-May-08 7:58 
Hi everybody,

I'm feeling a bit dumb here - right now I'm learning some of the nice features of C# 3.0 and can't get this code to compile:

public class Customer
{
   public int Id { get; set; }
   public string Name { get; set; }
   public string City { get; set; }

   public Customer() { }
}

List<Customer> listOfCustomers =
   new List<Customer> {
      { Id = 1, Name="Dave", City="Sarasota" },
      { Id = 2, Name="John", City="Tampa" },
      { Id = 3, Name="Abe", City="Miami" }
   };


Errors are, for each item in the array:

The name 'Id' does not exist in the current context
The name 'City' does not exist in the current context


What's wrong with this code? I've taken the example code from this site[^]

I'm using VS 2008 with .NET 3.5 as target platform.

regards

modified on Tuesday, May 13, 2008 3:11 PM


modified 12-Sep-18 21:01pm.

AnswerRe: Problem with C# 3.0 Collection and Object Initializers Pin
Gareth H13-May-08 9:06
Gareth H13-May-08 9:06 
GeneralRe: Problem with C# 3.0 Collection and Object Initializers Pin
User 665813-May-08 9:13
User 665813-May-08 9:13 
GeneralRe: Problem with C# 3.0 Collection and Object Initializers Pin
Gareth H13-May-08 9:36
Gareth H13-May-08 9:36 
AnswerRe: Problem with C# 3.0 Collection and Object Initializers Pin
Ed.Poore13-May-08 10:20
Ed.Poore13-May-08 10:20 
GeneralRe: Problem with C# 3.0 Collection and Object Initializers Pin
User 665813-May-08 10:39
User 665813-May-08 10:39 
GeneralRe: Problem with C# 3.0 Collection and Object Initializers Pin
Ed.Poore13-May-08 11:14
Ed.Poore13-May-08 11:14 
QuestionHelp can't find how retrieve element in a list!! Pin
papy-boom13-May-08 5:34
papy-boom13-May-08 5:34 
AnswerRe: Help can't find how retrieve element in a list!! Pin
User 665813-May-08 7:41
User 665813-May-08 7:41 
AnswerRe: Help can't find how retrieve element in a list!! Pin
Christian Graus13-May-08 13:22
protectorChristian Graus13-May-08 13:22 
GeneralRe: Help can't find how retrieve element in a list!! Pin
papy-boom13-May-08 22:35
papy-boom13-May-08 22:35 
QuestionEnsure a parameter is not null Pin
-Dy13-May-08 5:20
-Dy13-May-08 5:20 
GeneralRe: Ensure a parameter is not null Pin
CPallini13-May-08 5:43
mveCPallini13-May-08 5:43 
AnswerRe: Ensure a parameter is not null Pin
User 665813-May-08 7:25
User 665813-May-08 7:25 
AnswerRe: Ensure a parameter is not null Pin
Dave Sexton13-May-08 10:43
Dave Sexton13-May-08 10:43 
GeneralRe: Ensure a parameter is not null Pin
Vikram A Punathambekar13-May-08 19:06
Vikram A Punathambekar13-May-08 19:06 
AnswerRe: Ensure a parameter is not null Pin
Christian Graus13-May-08 11:45
protectorChristian Graus13-May-08 11:45 
GeneralRe: Ensure a parameter is not null Pin
Malcolm Smart13-May-08 12:35
Malcolm Smart13-May-08 12:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.