SlideShare a Scribd company logo
  Basics of C# 2008 .NET 3.0/3.5
Session Objectives What is C#? Understand the basic structure of a C# program.  Obtain a basic familiarization of what a "Namespace" is.  Obtain a basic understanding of what a  Class  is.  Learn what a  Main  method does.  Learn how to obtain command-line input.  Learn about console input/output (I/O).
Basic Structure of C# Program // Namespace Declaration using System; // Program start class class WelcomeCSS {     // Main begins program execution.     static void Main()     {         // Write to console         Console.WriteLine("Welcome to the C# !");      } }
Getting Command-Line Input What is meant by command line arguments? How to take command line input? How to convert command line input to required type? Structure of  Main() method in C#
Interactive via Command Line Taking input from user interactively Usage of Console.ReadLine() Conversion Functions
Object Oriented Programming Fundamentals Class Object Method Attribute Abstraction Encapsulation Polymorphism Inheritance Differences b/w object based and OO languages
Console Application in VS 2008 What is Solution (.sln)? IntelliSense Automatic Syntax checking Properties Window Solution Explorer Server Explorer
Basics Variables Initialization of Variables Scope of Variables Scope Clashes for Local Variables Scope Clashes for Fields and Local Variables Constants C# Data Types Value Types Reference Types
Integer Types Name CTS Type Description sbyte System.Sbyte 8-bit signed integer short  System.Int16 16-bit signed integer int  System.Int32 32-bit signed integer long System.Int64 64-bit signed integer byte  System.Byte 8-bit unsigned integer ushort  System.UInt16 16-bit unsigned integer uint  System.UInt32 32-bit unsigned integer ulong System.UInt64 64-bit unsigned integer
Floating-Point Types Name CTS Type Description float  System.Single 32-bit single-precision floating point double  System.Double 64-bit double precision floating point
Decimal Type Name CTS Type Description decimal  System.Decimal 128-bit high precision decimal notation
Boolean Type bool  type can store either true/false.
Character Type Name CTS Type Description char  System.Char 16-bit Unicode character
Escape Sequences Escape Sequence Character \’ Single quotation mark \” Double quotation mark \\ Backslash \0 Null \a Alert \b Backspace \f Form feed \n  New line \r Carriage return \t Tab character \v Vertial tab
Predefined Reference Types Name CTS Type Description object  System.Object The root type string  System.String Unicode character string
Object Type
Methods of Object Type Equals() GetHashCode() GetType() ToString()
The string Type
Operators in C# Arithmetic  +, -, *, /, % Logical  &, |, ^, ~, &&, ||, ! Comparison  ==, !=, <, >, <=, >= String Concatenation  + Increment and Decrement  ++, -- Bit Shifting (<<, >>) Assignment  =, +=, -=, /=, %=, ^=, &=, |=, ^=, <<=, >>= Member Access  .
Operators in C# (contd…) Indexing  [] Casting  ( ) Conditional  ?: Delegate Concatenation and removal  +,- Object Creation  (new) Size information  (sizeof, typeof, is, as) Overflow exception control (checked, unchecked) Namespace alias qualifier  :: Operator Shortcuts
checked operator byte  b=255; checked  { b++; } Console.WriteLine(b.ToString()); When executed, it throws an Exception
unchecked operator byte  b=255; unchecked  { b++; } Console.WriteLine(b.ToString()); It won’t throw Exception. However, data would be lost.
is operator Used to check whether an object is compatible with a type. Eg: int x=10; if(x is object) Cosole.WriteLine(“x is an object”);
as operator Used to perform explicit type conversions of reference types. object o1=“Some String”; string s1=o1 as string;
sizeof operator Used to find size required by a type on stack. unsafe  { Console.WriteLine(sizeof(int)); } Unsafe has to be used when we use pointers.
typeof operator Used to find the Sysem.Type object representing  a specified type. Eg: Console.WriteLine(typeof(string));
Type Conversions Implicit Explicit
Boxing and Unboxing
Flow Control Conditional Statements Loops Jump Statements
Conditional Statements if if – else if – else if – else switch
Loops while  do… while for  foreach
Jump Statements goto  break continue  return
Enumerations Example Switch example with enumeration
Arrays
Namespaces
using Statement
More on Compiling Options Option Output /t:exe A console application (default) /t:library A class library with manifest /t:module A component without a manifest /t:winexe A windows application (without a console window)
Console I/O Console.ReadLine() Console.WriteLine() Console.Read() ConsoleWrite()
Using Comments Internal Comments Single-line (//) Multiline (/*  */) XML Documentation Comments  (///) Csc /t:library /doc:Math.xml  Math.cs
Ad

More Related Content

What's hot (20)

[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
C sharp
C sharpC sharp
C sharp
Satish Verma
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
baabtra.com - No. 1 supplier of quality freshers
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
C# in depth
C# in depthC# in depth
C# in depth
Arnon Axelrod
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
OUM SAOKOSAL
 
C# Basics
C# BasicsC# Basics
C# Basics
Sunil OS
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
Jussi Pohjolainen
 

Similar to C# basics (20)

Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
Bhushan Mulmule
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
CSharp_02_LanguageOverview_andintroduction
CSharp_02_LanguageOverview_andintroductionCSharp_02_LanguageOverview_andintroduction
CSharp_02_LanguageOverview_andintroduction
Ranjithsingh20
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
Hossein Zahed
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
Abed Bukhari
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
C# Language Overview Part I
C# Language Overview Part IC# Language Overview Part I
C# Language Overview Part I
Doncho Minkov
 
Linq intro
Linq introLinq intro
Linq intro
Bình Trọng Án
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
Intro C# Book
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
Richard Thomson
 
PostThis
PostThisPostThis
PostThis
testingphase
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
sagaroceanic11
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamic
Gieno Miao
 
C#
C#C#
C#
Sudhriti Gupta
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
psundarau
 
Cpprm
CpprmCpprm
Cpprm
Shawne Lee
 
Visual c sharp
Visual c sharpVisual c sharp
Visual c sharp
Palm Palm Nguyễn
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
Bhushan Mulmule
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
CSharp_02_LanguageOverview_andintroduction
CSharp_02_LanguageOverview_andintroductionCSharp_02_LanguageOverview_andintroduction
CSharp_02_LanguageOverview_andintroduction
Ranjithsingh20
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
Hossein Zahed
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
C# Language Overview Part I
C# Language Overview Part IC# Language Overview Part I
C# Language Overview Part I
Doncho Minkov
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
Intro C# Book
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
Richard Thomson
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamic
Gieno Miao
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
psundarau
 
Ad

More from Dinesh kumar (11)

Cv
CvCv
Cv
Dinesh kumar
 
Dinesh cv
Dinesh cvDinesh cv
Dinesh cv
Dinesh kumar
 
Dinesh cv
Dinesh cvDinesh cv
Dinesh cv
Dinesh kumar
 
Data management with ado
Data management with adoData management with ado
Data management with ado
Dinesh kumar
 
Asp.net
 Asp.net Asp.net
Asp.net
Dinesh kumar
 
My resume
My resumeMy resume
My resume
Dinesh kumar
 
Dinesh ppt -windows 7
Dinesh ppt -windows 7Dinesh ppt -windows 7
Dinesh ppt -windows 7
Dinesh kumar
 
Functional specs
Functional specsFunctional specs
Functional specs
Dinesh kumar
 
Screen shots
Screen shotsScreen shots
Screen shots
Dinesh kumar
 
technology@web
technology@webtechnology@web
technology@web
Dinesh kumar
 
Web2 0
Web2 0Web2 0
Web2 0
Dinesh kumar
 
Ad

C# basics

  • 1. Basics of C# 2008 .NET 3.0/3.5
  • 2. Session Objectives What is C#? Understand the basic structure of a C# program. Obtain a basic familiarization of what a &quot;Namespace&quot; is. Obtain a basic understanding of what a Class is. Learn what a Main method does. Learn how to obtain command-line input. Learn about console input/output (I/O).
  • 3. Basic Structure of C# Program // Namespace Declaration using System; // Program start class class WelcomeCSS {     // Main begins program execution.     static void Main()     {         // Write to console         Console.WriteLine(&quot;Welcome to the C# !&quot;);      } }
  • 4. Getting Command-Line Input What is meant by command line arguments? How to take command line input? How to convert command line input to required type? Structure of Main() method in C#
  • 5. Interactive via Command Line Taking input from user interactively Usage of Console.ReadLine() Conversion Functions
  • 6. Object Oriented Programming Fundamentals Class Object Method Attribute Abstraction Encapsulation Polymorphism Inheritance Differences b/w object based and OO languages
  • 7. Console Application in VS 2008 What is Solution (.sln)? IntelliSense Automatic Syntax checking Properties Window Solution Explorer Server Explorer
  • 8. Basics Variables Initialization of Variables Scope of Variables Scope Clashes for Local Variables Scope Clashes for Fields and Local Variables Constants C# Data Types Value Types Reference Types
  • 9. Integer Types Name CTS Type Description sbyte System.Sbyte 8-bit signed integer short System.Int16 16-bit signed integer int System.Int32 32-bit signed integer long System.Int64 64-bit signed integer byte System.Byte 8-bit unsigned integer ushort System.UInt16 16-bit unsigned integer uint System.UInt32 32-bit unsigned integer ulong System.UInt64 64-bit unsigned integer
  • 10. Floating-Point Types Name CTS Type Description float System.Single 32-bit single-precision floating point double System.Double 64-bit double precision floating point
  • 11. Decimal Type Name CTS Type Description decimal System.Decimal 128-bit high precision decimal notation
  • 12. Boolean Type bool type can store either true/false.
  • 13. Character Type Name CTS Type Description char System.Char 16-bit Unicode character
  • 14. Escape Sequences Escape Sequence Character \’ Single quotation mark \” Double quotation mark \\ Backslash \0 Null \a Alert \b Backspace \f Form feed \n New line \r Carriage return \t Tab character \v Vertial tab
  • 15. Predefined Reference Types Name CTS Type Description object System.Object The root type string System.String Unicode character string
  • 17. Methods of Object Type Equals() GetHashCode() GetType() ToString()
  • 19. Operators in C# Arithmetic +, -, *, /, % Logical &, |, ^, ~, &&, ||, ! Comparison ==, !=, <, >, <=, >= String Concatenation + Increment and Decrement ++, -- Bit Shifting (<<, >>) Assignment =, +=, -=, /=, %=, ^=, &=, |=, ^=, <<=, >>= Member Access .
  • 20. Operators in C# (contd…) Indexing [] Casting ( ) Conditional ?: Delegate Concatenation and removal +,- Object Creation (new) Size information (sizeof, typeof, is, as) Overflow exception control (checked, unchecked) Namespace alias qualifier :: Operator Shortcuts
  • 21. checked operator byte b=255; checked { b++; } Console.WriteLine(b.ToString()); When executed, it throws an Exception
  • 22. unchecked operator byte b=255; unchecked { b++; } Console.WriteLine(b.ToString()); It won’t throw Exception. However, data would be lost.
  • 23. is operator Used to check whether an object is compatible with a type. Eg: int x=10; if(x is object) Cosole.WriteLine(“x is an object”);
  • 24. as operator Used to perform explicit type conversions of reference types. object o1=“Some String”; string s1=o1 as string;
  • 25. sizeof operator Used to find size required by a type on stack. unsafe { Console.WriteLine(sizeof(int)); } Unsafe has to be used when we use pointers.
  • 26. typeof operator Used to find the Sysem.Type object representing a specified type. Eg: Console.WriteLine(typeof(string));
  • 29. Flow Control Conditional Statements Loops Jump Statements
  • 30. Conditional Statements if if – else if – else if – else switch
  • 31. Loops while do… while for foreach
  • 32. Jump Statements goto break continue return
  • 33. Enumerations Example Switch example with enumeration
  • 37. More on Compiling Options Option Output /t:exe A console application (default) /t:library A class library with manifest /t:module A component without a manifest /t:winexe A windows application (without a console window)
  • 38. Console I/O Console.ReadLine() Console.WriteLine() Console.Read() ConsoleWrite()
  • 39. Using Comments Internal Comments Single-line (//) Multiline (/* */) XML Documentation Comments (///) Csc /t:library /doc:Math.xml Math.cs