OUTPUT

OUTPUT

OUTPUT

In C#, there are several ways to output information to the console or to other output streams. Here are some of the most common ways:

WriteLine: This method writes a string followed by a line terminator to the console. For example:

				
					Console.WriteLine("Hello, world!");
				
			

This would output the text “Hello, world!” to the console and add a newline character at the end.

Console.Write: This method writes a string to the console without adding a line terminator. For example

				
					Console.Write("Enter your name: ");
				
			

This would output the text “Enter your name: ” to the console, without adding a newline character.

Console.ReadLine: This method reads a line of text from the console and returns it as a string. For example

				
					string name = Console.ReadLine();
				
			

This would prompt the user to enter a line of text, and then store the input in the name variable.

Write/WriteLine with string interpolation: You can use the $ symbol to create a string with placeholders for variables. For example:

				
					int age = 30;
Console.WriteLine($"My age is {age} years old.");

				
			

This would output the text “My age is 30 years old.” to the console.

WriteLine: This method writes a string to the debug output window in Visual Studio, which can be useful for debugging purposes. For example:

				
					Debug.WriteLine("An error occurred.");
				
			

This would write the text “An error occurred.” to the debug output window in Visual Studio.

These are just a few examples of the many ways to output information in C#. Depending on your specific use case, you may need to use other methods or output streams.

Join To Get Our Newsletter
Spread the love