Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# inline conditional nullabel value types [duplicate]

Possible Duplicate:
Conditional operator assignment with Nullable<value> types?

in the following code snippet company.ParentID is a int? and parrent a reference type. this code is a syntax error. is there anyway to fix this inline conditional??

company.ParentID = (parent == null ? null: (parent.ID));

like image 412
omid.n Avatar asked Jul 28 '11 06:07

omid.n


People also ask

What C is used for?

C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Why is C named so?

Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".

What is C of computer?

" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.


1 Answers

Cast parent.Id to an int?

company.ParentID = (parent == null) ? null : (int?)parent.ID;

like image 188
jdasilva Avatar answered Sep 17 '22 23:09

jdasilva