Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 4, 2011 3:50 PM
Hi,
I came across this method, not sure what does ? do and why it is there.
thanks
Bob
public int? SubmitApportionmentValues( string program, int Year, int fiscalYear,
Dictionary<string, string> values )
All replies (2)
Tuesday, January 4, 2011 3:55 PM ✅Answered
Hi,
this is known as a nullable type. Taken from the documentation (http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=VS.100).aspx):
Nullable types are instances of the System.Nullable<T> struct. A nullable type can represent the correct range of values for its underlying value type, plus an additional null value. For example, a Nullable<Int32>, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A Nullable<bool> can be assigned the values true false, or null. The ability to assign null to numeric and Boolean types is especially useful when you are dealing with databases and other data types that contain elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.
You can now write something like
int? i = null;
Grz, Kris.
Thursday, January 6, 2011 2:05 AM ✅Answered
Actually the method SubmitApportionmentValues returns a nullable type integer, means return value can be null or integer.
To get the return value you may use a nullable interger or int.
Below I am providing sample code to get the value into int type and into nullable integet type:
To get the return value in int type :
int i = SubmitApportionmentValues(program,Year,fiscalYear,values) ?? 0;
here if the return type is null then value of i is 0 you may use anything else.
To get the return value in nullable integer type :
int? i = SubmitApportionmentValues(program,Year,fiscalYear,values);