Q1: What is the output of the following code?
int a = 20;
int? b = 30;
int? c = null;
Console.WriteLine(a + c ?? b);
result is 30
int? indicates b and c are nullable types
The result of 20+null is null.
?? operator checks whether the value of a+c is null, it returns a+c if it isn't null, returns b if it is null.
?? operator works for both reference and value types.
?? operator works for both reference and value types.
var s= "Hello";
s = 5;
s = 5++;
Console.WriteLine(s);
Cannot compile, error is "cannot implicitly convert
type 'int' to 'string'
No comments:
Post a Comment