Click here to Skip to main content
15,900,511 members
Home / Discussions / C#
   

C#

 
AnswerRe: how can i read a black pixel in binary image and displays it on a test box?? Pin
Christian Graus13-May-08 19:04
protectorChristian Graus13-May-08 19:04 
QuestionEvent firing in selectIndexChanged event Pin
steve_rm13-May-08 18:36
steve_rm13-May-08 18:36 
AnswerRe: Event firing in selectIndexChanged event Pin
Christian Graus13-May-08 19:05
protectorChristian Graus13-May-08 19:05 
QuestionGet Member Reference Pin
csharpguy7613-May-08 16:15
csharpguy7613-May-08 16:15 
QuestionDataGridView and Control Box Closing Pin
paas13-May-08 9:07
paas13-May-08 9:07 
QuestionAvoid contextmenustrip pop-up Pin
baranils13-May-08 9:00
baranils13-May-08 9:00 
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 
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 
He's got himself all confused to put it bluntly.  You can initialise collections using the new expressions, however you have to do as Gareth H pointed out, i.e.:
var customers = new List<Customer>()
{
    new Customer() { Id = 0, Name = "Dave", City = "Sarasota" },
    // ...
};
Where he's got mixed up is with the anonymous types, you could if you don't need to use the customers outside your existing method do the following:
var customers = new[]
{
    new { Id = 0, Name = "Dave", City = "Sarasota" },
    new { Id = 1, Name = "Ed", City = "London" },
};
foreach (var customer in customers)
{
    Console.WriteLine("{0} [{1}]", customer.Name, customer.City);
}
Which means you don't have to explicitly create a class to hold the data.  However as I mentioned you cannot pass this data (directly) to another class or even function within the same class.  What the compiler does is generate a "random" new class automatically (something like <>A_$72832$ for example, which is illegal in anything but IL).

But you can't mix the two, although it would save a little typing.


I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder

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 

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.