Possible Duplicate:
? (nullable) operator in C#
In System.Windows.Media.Animation I see the code as follows:
public double? By { get; set; }
What does the ? operator do here? Does anyone know?
I've tried to google this but it's hard to search for the operator if you don't know what its called by name. I've checked the page on Operators (http://msdn.microsoft.com/en-us/library/6a71f45d(v=vs.80).aspx) but the ? operator is not listed there.
Thanks!
In other words, we can also say that an operator is a symbol that tells the compiler to perform specific mathematical, conditional, or logical functions. It is a symbol that operates on a value or a variable. For example, + and - are the operators to perform addition and subtraction in any C program.
It means to perform a bitwise operation with the values on the left and right-hand side, and then assign the result to the variable on the left, so a bit of a short form.
Summary. An operator is a symbol which operates on a variable or value. There are types of operators like arithmetic, logical, conditional, relational, bitwise, assignment operators etc. Some special types of operators are also present in C like sizeof(), Pointer operator, Reference operator etc.
The ? is a type decorator. T? is the same as Nullable<T>, i.e. a nullable value type.
The documentation of the By property explains why it’s used here:
The property controls how A DoubleAnimation progresses; but instead of setting the By property, you can also set the From and To properties (or either) to control animation progress. Every combination of properties (except To and By) is allowed, so there needs to be a way to signal that a property is not set – hence it’s nullable.
Use the
Byproperty when you want to animate a value "by" a certain amount, rather than specifying a starting or ending value. You may also use theByproperty with theFromproperty.
The ? means it's nullable (the value can be set to null.
Nullable Types (C# Programming Guide)
This is not an operator. Rather, this is a special shorthand syntax for declaring nullable values.
It is nullable propertie, that means that you can set By = null, without ? you'll get error that double cant be null
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