Click here to Skip to main content
15,939,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I found a return statement that I cannot undertand.

return new EgmEventRaisedCommand()
{ EgmEvent = EGMEventUtils.GetEGMBillStackerEvent(state)

where class1 is a class and class2 is another class whose method(Method1) is called.
Can someone Please explain to me what will happen

What I have tried:

I've searched but didn't get any good explanation
Updated 29-Apr-16 0:38am
OriginalGriff 29-Apr-16 4:00am    
Show us the exact line of code (and the method header declaration the return is exiting from) - I suspect it doesn't look exactly like the code you show!
Karthik_Mahalingam 29-Apr-16 4:02am    
wrong syntax, post full code.
Member 12492612 29-Apr-16 6:04am    
Ive updated the code. Help me please....

1 solution

The exact code is always useful!

The code is pretty simple: it's a basic constructor with a property initialization:
MyClass mc = new MyClass() { MyProperty = "value" };
Is doing the same thing.
It's a "shortcut" way to do this:
MyClass mc = new MyClass();
mc.MyProperty = "value";

In your case, it's the same as writing:
EgmEventRaisedCommand eerc = new EgmEventRaisedCommand();
eerc.EgmEvent = EGMEventUtils.GetEGMBillStackerEvent(state);
return eerc;
Share this answer
Member 12492612 29-Apr-16 8:23am    
Thank u sooo much
OriginalGriff 29-Apr-16 8:27am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900