Click here to Skip to main content
15,902,939 members
Home / Discussions / C#
   

C#

 
AnswerRe: Multiple lines : datagridview Pin
Richard MacCutchan13-Nov-11 22:42
mveRichard MacCutchan13-Nov-11 22:42 
AnswerRe: Multiple lines : datagridview Pin
thatraja14-Nov-11 2:05
professionalthatraja14-Nov-11 2:05 
QuestionCheckers Board game error Pin
xnaLearner13-Nov-11 11:03
xnaLearner13-Nov-11 11:03 
AnswerRe: Checkers Board game error Pin
Pete O'Hanlon13-Nov-11 11:27
mvePete O'Hanlon13-Nov-11 11:27 
QuestionMessage Removed Pin
13-Nov-11 9:24
AghaKhan13-Nov-11 9:24 
AnswerRe: What this mean ??. This code works fine Pin
Luc Pattyn13-Nov-11 9:33
sitebuilderLuc Pattyn13-Nov-11 9:33 
GeneralRe: What this mean ??. This code works fine Pin
AghaKhan13-Nov-11 16:00
AghaKhan13-Nov-11 16:00 
AnswerRe: What this mean ??. This code works fine. [Edited to show message which OP deleted] Pin
Pete O'Hanlon13-Nov-11 9:44
mvePete O'Hanlon13-Nov-11 9:44 
The ?? is known as the null coalescing operator. That's a fancy dance way of saying that it tests to see if the left hand side is null, and if it is, it uses the right hand side. What this is doing, in your example, is evaluate items to see if it's null, and if it is, it assigns a new list to it and returns that. In practical terms, this is the same as doing this:
C#
if (items == null)
  items = new List<Item>();
return items
I have missed the addition of the Item instances to the array to simplify this example, but you should get the idea from it.

[Edit]The OP deleted the original message. It was:

public class Item
{
public double X { get; set; }
public double Y { get; set; }
public string Name { get; set; }
public string Color { get; set; }
}

public class ItemsFactory
{
private List items;
public IEnumerable Items
{
get
{
return items ?? (items = new List<item>()
{
new Item { Name = "One", X = 33, Y = 25, Color = "Red" }, new
new Item { Name = "Two", X = 44, Y = 99, Color"Blue" }
});
}
}
}

Forgive your enemies - it messes with their heads

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility



modified 14-Nov-11 6:11am.

GeneralRe: What this mean ??. This code works fine Pin
AnnieMacD13-Nov-11 9:49
AnnieMacD13-Nov-11 9:49 
GeneralRe: What this mean ??. This code works fine Pin
Pete O'Hanlon13-Nov-11 10:03
mvePete O'Hanlon13-Nov-11 10:03 
GeneralRe: What this mean ??. This code works fine Pin
AghaKhan13-Nov-11 16:00
AghaKhan13-Nov-11 16:00 
RantRe: What this mean ??. This code works fine Pin
Smithers-Jones13-Nov-11 22:54
Smithers-Jones13-Nov-11 22:54 
GeneralRe: What this mean ??. This code works fine Pin
Pete O'Hanlon14-Nov-11 0:12
mvePete O'Hanlon14-Nov-11 0:12 
QuestionC# beginer a deploy Q using report viwer Pin
pinifg13-Nov-11 2:56
pinifg13-Nov-11 2:56 
Questionis this good C# linq to sql code? Pin
Member 821751712-Nov-11 14:17
Member 821751712-Nov-11 14:17 
AnswerRe: is this good C# linq to sql code? Pin
Not Active12-Nov-11 16:32
mentorNot Active12-Nov-11 16:32 
GeneralRe: is this good C# linq to sql code? Pin
Member 821751713-Nov-11 13:17
Member 821751713-Nov-11 13:17 
GeneralRe: is this good C# linq to sql code? Pin
Not Active13-Nov-11 13:52
mentorNot Active13-Nov-11 13:52 
AnswerRe: is this good C# linq to sql code? Pin
SledgeHammer0113-Nov-11 7:17
SledgeHammer0113-Nov-11 7:17 
GeneralRe: is this good C# linq to sql code? Pin
Richard Andrew x6413-Nov-11 7:58
professionalRichard Andrew x6413-Nov-11 7:58 
GeneralRe: is this good C# linq to sql code? Pin
Not Active13-Nov-11 13:49
mentorNot Active13-Nov-11 13:49 
GeneralRe: is this good C# linq to sql code? Pin
SledgeHammer0113-Nov-11 13:59
SledgeHammer0113-Nov-11 13:59 
GeneralRe: is this good C# linq to sql code? Pin
Not Active13-Nov-11 14:05
mentorNot Active13-Nov-11 14:05 
GeneralRe: is this good C# linq to sql code? Pin
SledgeHammer0113-Nov-11 14:27
SledgeHammer0113-Nov-11 14:27 
GeneralRe: is this good C# linq to sql code? Pin
BobJanova13-Nov-11 22:30
BobJanova13-Nov-11 22:30 

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.