C# class INTRODUCTION
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.
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;
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!");
}
}
}
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");
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);

C# Class Introduction

  • 1.
  • 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 Mainmethod • 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 writingto 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 towrite 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);