KEMBAR78
C# basics | PPT
  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

C# basics

  • 1.
    Basicsof C# 2008 .NET 3.0/3.5
  • 2.
    Session Objectives Whatis 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 ofC# 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 InputWhat 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 CommandLine Taking input from user interactively Usage of Console.ReadLine() Conversion Functions
  • 6.
    Object Oriented ProgrammingFundamentals Class Object Method Attribute Abstraction Encapsulation Polymorphism Inheritance Differences b/w object based and OO languages
  • 7.
    Console Application inVS 2008 What is Solution (.sln)? IntelliSense Automatic Syntax checking Properties Window Solution Explorer Server Explorer
  • 8.
    Basics Variables Initializationof 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 NameCTS 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 NameCTS Type Description float System.Single 32-bit single-precision floating point double System.Double 64-bit double precision floating point
  • 11.
    Decimal Type NameCTS Type Description decimal System.Decimal 128-bit high precision decimal notation
  • 12.
    Boolean Type bool type can store either true/false.
  • 13.
    Character Type NameCTS Type Description char System.Char 16-bit Unicode character
  • 14.
    Escape Sequences EscapeSequence 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 TypesName CTS Type Description object System.Object The root type string System.String Unicode character string
  • 16.
  • 17.
    Methods of ObjectType Equals() GetHashCode() GetType() ToString()
  • 18.
  • 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 Usedto 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 Usedto perform explicit type conversions of reference types. object o1=“Some String”; string s1=o1 as string;
  • 25.
    sizeof operator Usedto 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 Usedto find the Sysem.Type object representing a specified type. Eg: Console.WriteLine(typeof(string));
  • 27.
  • 28.
  • 29.
    Flow Control ConditionalStatements Loops Jump Statements
  • 30.
    Conditional Statements ifif – else if – else if – else switch
  • 31.
    Loops while do… while for foreach
  • 32.
    Jump Statements goto break continue return
  • 33.
    Enumerations Example Switchexample with enumeration
  • 34.
  • 35.
  • 36.
  • 37.
    More on CompilingOptions 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 InternalComments Single-line (//) Multiline (/* */) XML Documentation Comments (///) Csc /t:library /doc:Math.xml Math.cs