Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
var startDateParameter = startDate.HasValue ?
new ObjectParameter("StartDate", startDate) :
new ObjectParameter("StartDate", typeof(System.DateTime));
Posted

It's a Conditional operator: '?:' which is effectively an "inline-if" statement.
C#
A = B ? C : D;

If B is true, then C is assigned to A, otherwise D is.
So your code could be written as:
C#
var startDateParameter;
if (startDate.HasValue)
   {
   startDateParameter = new ObjectParameter("StartDate", startDate);
   }
else
   {
   startDateParameter = new ObjectParameter("StartDate", typeof(System.DateTime));
   }
which should be a bit more obvious.
Indenting the original mighthave helped clarity:
C#
var startDateParameter = startDate.HasValue ? new ObjectParameter("StartDate", startDate) 
                                            : new ObjectParameter("StartDate", typeof(System.DateTime));
Or
C#
var startDateParameter = startDate.HasValue 
                         ? new ObjectParameter("StartDate", startDate) 
                         : new ObjectParameter("StartDate", typeof(System.DateTime));
Perhaps.
 
Share this answer
 
Comments
sachet sharma 24-Jul-14 5:37am    
startDateParameter = new ObjectParameter("StartDate", startDate);

why object paramete are used here
are we assigning startdate to startdateparameter
nd what this mean new ObjectParameter("StartDate", startDate);
OriginalGriff 24-Jul-14 6:11am    
There you would have to look at the wider context of the code that snippet is in.
You would be best asking the person who wrote it!
sachet sharma 24-Jul-14 7:32am    
okay buddy thanx
OriginalGriff 24-Jul-14 7:34am    
You're welcome!
A bit of documentation helps: ?: Operator[^].
 
Share this answer
 

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