Reading from the console => Console.ReadLine
Writing to the console => Console.WriteLine
Two ways to write a console
1. Concatenation
2. Place holder which is most preferred
Example with Concatenation
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter First Name");
string FirstName = Console.ReadLine();
Console.WriteLine("Enter Last Name");
string LastName = Console.ReadLine();
Console.WriteLine("Hello "+FirstName +LastName);
Console.ReadLine();
}
}
Output:
Enter First Name
Balamurugan
Enter Last Name
Ganesan
Hello BalamuruganGanesan
Example with Place holder
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter First Name");
string FirstName = Console.ReadLine();
Console.WriteLine("Enter Last Name");
string LastName = Console.ReadLine();
Console.WriteLine("Hello {0} {1}", FirstName, LastName);
Console.ReadLine();
}
}
Output
Note1:
C# is a case sensitive
Note2:
Difference between Write and WriteLine
Write() method => Output values to the screen without newline character
WriteLine() method => Output will start on a new line
Writing to the console => Console.WriteLine
Two ways to write a console
1. Concatenation
2. Place holder which is most preferred
Example with Concatenation
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter First Name");
string FirstName = Console.ReadLine();
Console.WriteLine("Enter Last Name");
string LastName = Console.ReadLine();
Console.WriteLine("Hello "+FirstName +LastName);
Console.ReadLine();
}
}
Output:
Enter First Name
Balamurugan
Enter Last Name
Ganesan
Hello BalamuruganGanesan
Example with Place holder
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter First Name");
string FirstName = Console.ReadLine();
Console.WriteLine("Enter Last Name");
string LastName = Console.ReadLine();
Console.WriteLine("Hello {0} {1}", FirstName, LastName);
Console.ReadLine();
}
}
Output
Note1:
C# is a case sensitive
Note2:
Difference between Write and WriteLine
Write() method => Output values to the screen without newline character
WriteLine() method => Output will start on a new line
No comments:
Post a Comment