using System; public class MainClass { static void Main(string[] args) { // Change the console appearance and redisplay. Console.Title = "Resized Console"; Console.ResetColor(); Console.Clear(); Console.SetWindowSize(100, 50); Console.BufferHeight = 500; Console.BufferWidth = 100; Console.CursorLeft = 20; Console.CursorSize = 50; Console.CursorTop = 20; Console.CursorVisible = false; } }
CursorVisible ResetColor SetWindowSize BufferHeight BufferWidth CursorLeft CursorSize CursorTop
using System; public class MainClass { static void Main(string[] args) { // Change the console appearance and redisplay. Console.Title = "Resized Console"; Console.ResetColor(); Console.Clear(); Console.SetWindowSize(100, 50); Console.BufferHeight = 500; Console.BufferWidth = 100; Console.CursorLeft = 20; Console.CursorSize = 50; Console.CursorTop = 20; Console.CursorVisible = false; } }
Displaying the sum of two numbers input from the keyboard.
using System; public class Addition { public static void Main( string[] args ) { int number1; int number2; int sum; Console.Write( "Enter first integer: " ); number1 = Convert.ToInt32( Console.ReadLine() ); Console.Write( "Enter second integer: " ); number2 = Convert.ToInt32( Console.ReadLine() ); sum = number1 + number2; Console.WriteLine( "Sum is {0}", sum ); } }
Printing multiple lines of text with string formatting.
using System; public class Welcome4 { public static void Main( string[] args ) { Console.WriteLine( "{0} {1}", "Welcome to", "C# Programming!" ); } }
Printing multiple lines with a single statement.
using System; public class Welcome3 { public static void Main( string[] args ) { Console.WriteLine( "Welcome to C# Programming!" ); } }
Printing one line of text with multiple statements.
using System; public class Welcome2 { public static void Main(string[] args) { Console.Write("Welcome to "); Console.WriteLine("C# Programming!"); } }
WriteLine and Write
using System; class ConsoleAdder { public static void Main() { int a = 15; int b = 744; int c = a + b; Console.Write("The sum of "); Console.Write(a); Console.Write(" and "); Console.Write(b); Console.Write(" equals "); Console.WriteLine(c); Console.WriteLine("The sum of " + a + " and " + b + " equals " + c); Console.WriteLine("The sum of {0} and {1} equals {2}", a, b, c); } }