Venciity

[ Telerik C#] Primitives And Variables - EX 13

Feb 13th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. // 13. Create a program that assigns null values to an integer and to double variables.
  2. // Try to print them on the console, try to add some values or the null literal to them and see the result.
  3.  
  4.  
  5. using System;
  6. using System.Text;
  7.  
  8.  
  9. class NullVariable
  10. {
  11.     static void Main()
  12.     {
  13.         int? a = null;
  14.         double? b = null;  // It means that the value type in question is a nullable type
  15.  
  16.         Console.WriteLine("Printing the nullable variables: a: {0} b: {1}", a, b);
  17.  
  18.         a += null;
  19.         b += 3.1415926; // !Important - Adding value to null variable results null!
  20.         Console.WriteLine("Printing the nullable variables: a: {0} b: {1}", a, b);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment