2. What is C#?
โข C# is a simple, modern, general-purpose, object-oriented programming language
โข Reasons make C# a widely used professional language โ
โข It is a modern, general-purpose programming language
โข It is object oriented.
โข It is component oriented.
โข It is easy to learn.
โข It is a structured language.
โข It produces efficient programs.
โข It can be compiled on a variety of computer platforms.
โข It is a part of .NET Framework.
3. What is Namespace?
โข A namespace is used to organize your code and is a collection of classes, interfaces, structs,
Enums and delegates.
โข Namespace Declaration:
โข The namespace declaration. using System, indicates that you are using The System namespace.
Example:
//Namespace Declaration
using System;
4. Purpose of Main method
โข Main method is the entry point into your application.
//Namespace Declaration
using System;
namespace Introduction
{
class Program
{
static void Main(string[]args)
{
//C# Tutorial - Introduction
//Write toconsole
Console.WriteLine("Welcome toC#Training!");
Main1();
}
static void Main1()
{
Console.WriteLine("Welcome toC#Training 1!");
}
}
}
5. Reading and writing to a console
Reading from the console:
Example:
//Read the string from console
var username= Console.ReadLine();
//Read theint fromconsole
int userNumber= int.Parse(Console.ReadLine());
Writing to the console:
Example:
//Prompt the user for his name
Console.WriteLine("Please enteryour name");
6. 2 ways to write to console:
Concatenation
Example:
//Concatenatenamewith hello word and print
Console.WriteLine("Hello "+ username);
Plate Holder syntax - Most Preferred
Example:
//Placeholder syntax to print namewith hello word -Most Preferred
Console.WriteLine("Hello {0}",username);
Console.WriteLine("Hello {0}{1}",firstname, lastname);