// Example application for code from // https://jonskeet.uk/csharp/parameters.html // // To compile the code, run (from a command prompt // with the appropriate environment variables set): // csc Example8.cs // // To run the code after compilation, just run Example8.exe using System; using System.Text; public class Example8 { static void Foo (out int x) { // Can't read x here - it's considered unassigned // Assignment - this must happen before the method can complete normally x = 10; // The value of x can now be read: int a = x; } public static void Main (string[] args) { // Declare a variable but don't assign a value to it int y; // Pass it in as an output parameter, even though its value is unassigned Foo (out y); // It's now assigned a value, so we can write it out: Console.WriteLine (y); } }