introductory-examples/definite-assignment/definite-assignment.cs - Demonstrations of definite assignment. | Lecture 2 - slide 14 : 43 Program 1 |
using System; class DefiniteAssignmentDemo{ public static void Main(){ int a, b; bool c; if (ReadFromConsole("Some Number") < 10){ a = 1; b = 2; } else { a = 2; } Console.WriteLine(a); Console.WriteLine(b); // Use of unassigned local variable 'b' while (a < b){ c = (a > b); a = Math.Max(a, b); } Console.WriteLine(c); // Use of unassigned local variable 'c' } public static int ReadFromConsole(string prompt){ Console.WriteLine(prompt); return int.Parse(Console.ReadLine()); } }