Basic -C# Reading and writing to a console
* Reading From the Console
* Writing to the Console
* Two Ways To Write Console
1) Concatenation
2) Place Holder Syntax
Reading and Writing to Console
using System; // A Namespace is used to Organize your code and is Collection of Classes
class Program
{
static void Main() // Main Methods
{
// Prompt The User For His First Name
Console.WriteLine("Enter First Name");
// Read the name from Console
string firstname = Console.ReadLine();
// Prompt the User For His Last Name
Console.WriteLine("Enter Last Name");
// Read the Last name from Console
string Lastname = Console.ReadLine();
// Concatenate
// Concatenate name with hello word and Print
Console.WriteLine("Hello " + firstname + Lastname);
// Placeholder syntex to Print Name
Console.WriteLine("Hello {0}", firstname);
Console.WriteLine("Hello {0}", Lastname);
Console.Read();
}
}
Namespace: A Namespace is used to Organize your code and is Collection of Classes
Example : Interface , Structs . Enums and Delegates.
Concatenate Definition : Concatenation is a process of appending one string to the end of another string.When you concatenate string literals or string constants by using the + operator.
Concatenate : Console.WriteLine("Hello" + firstname );
Placeholder Syntax : Console.WriteLine("Hello {0}", firstname )
Comments
Post a Comment