SlideShare a Scribd company logo
1 of 14
Dr. Neeraj Kumar Pandey
CSE Deptt. DITU
neeraj.pandey@dituniversity.edu.in
Introduction to C#
INDEX
• Introduction to C#.
• Why .NET ?
• Differences between C++ and C#.
• C# Program Structure & first program.
• Execution of C# Program.
• Adding Comments.
• Using Aliases for namespace.
Introduction to C#
• C# is a simple, modern object oriented programming language
developed by Microsoft .NET initiative led by Anders Hejlsberg.
• C# is very much based on C and C++.
• It is approved by European Computer Manufacturers Association
(ECMA) and International Standards Organization (ISO).
• 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.
Why C# ?
 It is derived from C and C++.
 Major parts of .NET framework are
coded in C#.
 C# is simple.
 C# is modern.
 C# is object oriented.
 C# is powerful and flexible.
 C# is modular.
 Interoperable.
 Versionable.
C++ Vs. C#
C++
• C++ is a general purpose, case-sensitive, free-
form programming language that supports
object-oriented, procedural and generic
programming.
• In C++, multiple inheritance is possible
through class.
• In C++, memory management is handled
manually.
• In C++, pointers can be used anywhere in a
program.
• C++ programming is based on OOPs concept.
• C++ is a programming language that runs on
all platforms.
• C++ programming can be used to create
console applications.
C#
• C# is pronounced as "C-Sharp". It is an object-
oriented programming language provided by
Microsoft that runs on .Net Framework.
• In C#, multiple inheritance is not possible
through class.
• In C#, memory management is handled
automatically.
• In C#, pointers can be used only in unsafe
mode.
• C# programming is based on Component and
OOPs concept.
• C# is a programming language that rarely used
outside Windows.
• C# programming can be used to create console
applications, Windows applications, Mobile
applications, etc.
C# Program Structure & first program.
C# consist of following things
Namespace declaration.
A Class.
Class methods.
Class attributes.
The Main method.
Statements and Expressions.
Comments.
C# Program Structure & First program.
C# used to develop two categories of programs.
1. Executable application programs .
Executable programs are written to carry out
certain tasks and require the method Main in one
of the class.
2. Component libraries.
Component libraries do not require a Main
declaration because they are not standalone
application programs. They written for use by
other applications.
C# Program Structure & first program.
using System: This "using" keyword is used to
contain the System namespace in the program. Every
program has multiple using statements.
namespace declaration: It’s a collection of classes.
The CSharp namespace contains the class
HelloWorld.
class declaration: The class HelloWorld contains the
data and method definitions that your program uses
and Classes always contain multiple methods.
using System;
namespace CSharp {
class HelloWorld {
public static void Main(string[] args) {
Console.WriteLine("Hello C#");
Console.WriteLine(“Press a key…”);
Console.ReadLine();
} } }
defines the Main method
This is the entry point for all C# programs. The main method states what the class does when
executed.
WriteLine()
It’s a method of the Console class distinct in the System namespace. This statement causes the
message "Hello, World!" to be displayed on the screen.
Console.ReadLine()
This is for the VS.NET Users. This makes the program wait for a key press.
C# Program Structure & first program.
using System;
namespace CSharp {
class HelloWorld {
static void Main(string[] args) {
Console.WriteLine("Hello C#");
Console.WriteLine(“Press a key…”);
Console.ReadLine();
} } }
namespaces: a namespace used to organize your code and is collection of classes, interfaces,
structs , enums and delegates.
Public: the keyword public is an access modifier that tells c# compiler that the Main method is
accessible by anyone.
Static : the keyword static declare that the Main method is global one and can be called without
creating an instance of the class.
Void: the keyword void is a type modifier that states that the Main method does not return any
value .
Execution of C# Program
1. Write source code in any editor (notepad, word pad etc.)
2. Save it with .cs extension (i.e, file_name.cs).
3. Open visual studio command prompt and go to the
directories containing your filename.
4. Compile the program by writing the command
csc file_name.cs
( c# compiler compile code and create an executable file
(IL code) by name file_name.exe
5. If the code is error free then execute the executable file by
file_name
ADDING COMMENT
C# PERMITS TWO TYPES OF COMMENTS
1. Single line comments : by using double backslash (//) symbol.
// this is an example of
//Multiple comments
//in C# Language
2. Multiple line comments:
Uses /* ………..*/ to write multiple line comments.
/* this is an example of
Multiple line
Comments in C# Language
*/
Using Aliases for namespace classes
System is a namespace and Console is a class. The using directive can be applied only to
Namespaces and can not be applied to classes therefore the statement is illegal
using System.Console;
To overcome this problem we used aliases for namespace classes.
using alias_name = class-name;
Example:
using A = System.Console;
Class Sample
{
Public static void main()
{
A.WriteLine(“Hello”);
}
}
Reading and Writing to Console
There are two ways to write to console:
a) Concatenation b) Place holder syntax (most prefer).
Ex.
using System;
namespace ConsoleApp7
{
class Program
{
static void Main()
{ int a;
System.Console.WriteLine("enter your first name");
string fname = Console.ReadLine();
string lname = Console.ReadLine();
System.Console.WriteLine("Hello " +fname +lname); //Concatenation method
System.Console.WriteLine("Hello {0} {1}",fname,lname); //place holder method
int.Parse(Console.ReadLine()); //Reading integer from Keyboard
System.Console.ReadLine(); // alternate method to fix the output screen
}
}
}
Using multiple classes
A program with two classes: only one class can have Main() method
class TestClass
{
public void fun()
{
Console.WriteLine("you are in second class");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("you are in main methods");
TestClass test = new TestClass();
test.fun();
} }

More Related Content

What's hot (20)

Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Json
JsonJson
Json
 
Javascript
JavascriptJavascript
Javascript
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
 
.NET Framework Overview
.NET Framework Overview.NET Framework Overview
.NET Framework Overview
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
 
Php string function
Php string function Php string function
Php string function
 
Asp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity FrameworkAsp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity Framework
 

Similar to C# lecture 1: Introduction to Dot Net Framework

Similar to C# lecture 1: Introduction to Dot Net Framework (20)

Structure of a C# Program
Structure of a C# ProgramStructure of a C# Program
Structure of a C# Program
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
 
C#.NET
C#.NETC#.NET
C#.NET
 
C# Class Introduction
C# Class IntroductionC# Class Introduction
C# Class Introduction
 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net framework
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
C# Class Introduction.pptx
C# Class Introduction.pptxC# Class Introduction.pptx
C# Class Introduction.pptx
 
Basics1
Basics1Basics1
Basics1
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
C programming
C programmingC programming
C programming
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
CS3251-_PIC
CS3251-_PICCS3251-_PIC
CS3251-_PIC
 
Learn C Programming Full Course Free
Learn C Programming Full Course FreeLearn C Programming Full Course Free
Learn C Programming Full Course Free
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
Programming
ProgrammingProgramming
Programming
 
Introduction of c# day3
Introduction of c# day3Introduction of c# day3
Introduction of c# day3
 

More from Dr.Neeraj Kumar Pandey (19)

Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Strings in c#
Strings in c#Strings in c#
Strings in c#
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
 
Dot net assembly
Dot net assemblyDot net assembly
Dot net assembly
 
Cloud introduction
Cloud introductionCloud introduction
Cloud introduction
 
Role of cloud computing in scm
Role of cloud computing in scmRole of cloud computing in scm
Role of cloud computing in scm
 
Public cloud
Public cloudPublic cloud
Public cloud
 
cloud computing Multi cloud
cloud computing Multi cloudcloud computing Multi cloud
cloud computing Multi cloud
 
Ibm bluemix case study
Ibm bluemix case studyIbm bluemix case study
Ibm bluemix case study
 
Business cases for the need of cloud computing
Business cases for the need of cloud computingBusiness cases for the need of cloud computing
Business cases for the need of cloud computing
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualization
 
cloud computing: Vm migration
cloud computing: Vm migrationcloud computing: Vm migration
cloud computing: Vm migration
 
Cloud Computing: Virtualization
Cloud Computing: VirtualizationCloud Computing: Virtualization
Cloud Computing: Virtualization
 
Dot net introduction
Dot net introductionDot net introduction
Dot net introduction
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 

Recently uploaded

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

C# lecture 1: Introduction to Dot Net Framework

  • 1. Dr. Neeraj Kumar Pandey CSE Deptt. DITU neeraj.pandey@dituniversity.edu.in Introduction to C#
  • 2. INDEX • Introduction to C#. • Why .NET ? • Differences between C++ and C#. • C# Program Structure & first program. • Execution of C# Program. • Adding Comments. • Using Aliases for namespace.
  • 3. Introduction to C# • C# is a simple, modern object oriented programming language developed by Microsoft .NET initiative led by Anders Hejlsberg. • C# is very much based on C and C++. • It is approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO). • 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.
  • 4. Why C# ?  It is derived from C and C++.  Major parts of .NET framework are coded in C#.  C# is simple.  C# is modern.  C# is object oriented.  C# is powerful and flexible.  C# is modular.  Interoperable.  Versionable.
  • 5. C++ Vs. C# C++ • C++ is a general purpose, case-sensitive, free- form programming language that supports object-oriented, procedural and generic programming. • In C++, multiple inheritance is possible through class. • In C++, memory management is handled manually. • In C++, pointers can be used anywhere in a program. • C++ programming is based on OOPs concept. • C++ is a programming language that runs on all platforms. • C++ programming can be used to create console applications. C# • C# is pronounced as "C-Sharp". It is an object- oriented programming language provided by Microsoft that runs on .Net Framework. • In C#, multiple inheritance is not possible through class. • In C#, memory management is handled automatically. • In C#, pointers can be used only in unsafe mode. • C# programming is based on Component and OOPs concept. • C# is a programming language that rarely used outside Windows. • C# programming can be used to create console applications, Windows applications, Mobile applications, etc.
  • 6. C# Program Structure & first program. C# consist of following things Namespace declaration. A Class. Class methods. Class attributes. The Main method. Statements and Expressions. Comments.
  • 7. C# Program Structure & First program. C# used to develop two categories of programs. 1. Executable application programs . Executable programs are written to carry out certain tasks and require the method Main in one of the class. 2. Component libraries. Component libraries do not require a Main declaration because they are not standalone application programs. They written for use by other applications.
  • 8. C# Program Structure & first program. using System: This "using" keyword is used to contain the System namespace in the program. Every program has multiple using statements. namespace declaration: It’s a collection of classes. The CSharp namespace contains the class HelloWorld. class declaration: The class HelloWorld contains the data and method definitions that your program uses and Classes always contain multiple methods. using System; namespace CSharp { class HelloWorld { public static void Main(string[] args) { Console.WriteLine("Hello C#"); Console.WriteLine(“Press a key…”); Console.ReadLine(); } } } defines the Main method This is the entry point for all C# programs. The main method states what the class does when executed. WriteLine() It’s a method of the Console class distinct in the System namespace. This statement causes the message "Hello, World!" to be displayed on the screen. Console.ReadLine() This is for the VS.NET Users. This makes the program wait for a key press.
  • 9. C# Program Structure & first program. using System; namespace CSharp { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Hello C#"); Console.WriteLine(“Press a key…”); Console.ReadLine(); } } } namespaces: a namespace used to organize your code and is collection of classes, interfaces, structs , enums and delegates. Public: the keyword public is an access modifier that tells c# compiler that the Main method is accessible by anyone. Static : the keyword static declare that the Main method is global one and can be called without creating an instance of the class. Void: the keyword void is a type modifier that states that the Main method does not return any value .
  • 10. Execution of C# Program 1. Write source code in any editor (notepad, word pad etc.) 2. Save it with .cs extension (i.e, file_name.cs). 3. Open visual studio command prompt and go to the directories containing your filename. 4. Compile the program by writing the command csc file_name.cs ( c# compiler compile code and create an executable file (IL code) by name file_name.exe 5. If the code is error free then execute the executable file by file_name
  • 11. ADDING COMMENT C# PERMITS TWO TYPES OF COMMENTS 1. Single line comments : by using double backslash (//) symbol. // this is an example of //Multiple comments //in C# Language 2. Multiple line comments: Uses /* ………..*/ to write multiple line comments. /* this is an example of Multiple line Comments in C# Language */
  • 12. Using Aliases for namespace classes System is a namespace and Console is a class. The using directive can be applied only to Namespaces and can not be applied to classes therefore the statement is illegal using System.Console; To overcome this problem we used aliases for namespace classes. using alias_name = class-name; Example: using A = System.Console; Class Sample { Public static void main() { A.WriteLine(“Hello”); } }
  • 13. Reading and Writing to Console There are two ways to write to console: a) Concatenation b) Place holder syntax (most prefer). Ex. using System; namespace ConsoleApp7 { class Program { static void Main() { int a; System.Console.WriteLine("enter your first name"); string fname = Console.ReadLine(); string lname = Console.ReadLine(); System.Console.WriteLine("Hello " +fname +lname); //Concatenation method System.Console.WriteLine("Hello {0} {1}",fname,lname); //place holder method int.Parse(Console.ReadLine()); //Reading integer from Keyboard System.Console.ReadLine(); // alternate method to fix the output screen } } }
  • 14. Using multiple classes A program with two classes: only one class can have Main() method class TestClass { public void fun() { Console.WriteLine("you are in second class"); } } class Program { static void Main(string[] args) { Console.WriteLine("you are in main methods"); TestClass test = new TestClass(); test.fun(); } }