I just ran across some code while working with System.DirectoryServices.AccountManagement
public DateTime? LastLogon { get; }
What is the ? after the DateTime for.
I found a reference for the ?? Operator (C# Reference), but it's not the same thing. (280Z28: Here is the correct link for Using Nullable Types.)
The bitwise OR assignment operator ( |= ) uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable.
C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.
This operator is a combination of '-' and '=' operators. This operator first subtracts the value on the right from the current value of the variable on left and then assigns the result to the variable on the left. Example: (a -= b) can be written as (a = a - b) If initially value stored in a is 8.
The ?
makes it a nullable type (it's shorthand for the Nullable<T>
Structure and is applicable to all value types).
Nullable Types (C#)
Note:
The ??
you linked to is the null coalescing operator which is completely different.
The ?
is not an operator in this case, it's part of the type. The syntax
DateTime?
is short for
Nullable<DateTime>
so it declares that LastLogon
is a property that will return a Nullable<DateTime>
. For details, see MSDN.
The ??
that you linked to is somewhat relevant here. That is the null-coalescing operator which has the following semantics. The expression
x ?? y
evaluates to y
if x
is null
otherwise it evaluates to x
. Here x
can be a reference type or a nullable type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With