ilm proprietary and confidential -
TRANSCRIPT
ILM Proprietary and Confidential - http://www.ilmservice.com
Native support for core .NET framework Supports traditional OO concepts such as
Inheritance Polymorphism Operator overloading
C/C++ like syntax No more global variables
C# Features
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;class Hello{ static void Main()
{ Console.WriteLine("Hello, world"); }}
A Simple C# Program
ILM Proprietary and Confidential - http://www.ilmservice.com
Can be single dimension or multi-dimension
class Test{ static void Main() { int[] a1 = new int[] {1, 2, 3}; int[,] a2 = new int[,] {{1, 2, 3}, {4, 5, 6}}; int[,,] a3 = new int[10, 20, 30];}
}
Arrays
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;
class Test
{static void Main(string[] args)
{if (args.Length == 0)
Console.WriteLine("No arguments were provided");
elseConsole.WriteLine("Arguments were
provided");
}
}
If Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;
class Test{static void Main(string[] args) {
switch (args.Length) {case 0:
Console.WriteLine("No arguments”); break;
case 1:Console.WriteLine("One
arguments”); break;
default:Console.WriteLine("{0}
arguments”); break;}
}}
Switch Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;
class Test{
static int Find(int value, int[] arr)
{int i = 0;while (arr[i] != value)
{ if (++i > arr.Length)
throw new ArgumentException();
}return i;
}
}
While Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;
class Test
{static void Main()
{ string s;
do
{ s = Console.ReadLine(); } while (s != "Exit");
}
}
Do Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;
class Test
{static void Main()
{for (int i = 0; i < 10; i++)
Console.WriteLine(i);}
}
For Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
using System;using System.Collections;
class Test{
static void WriteList(ArrayList list) {
foreach (object o in list) Console.WriteLine(o);
}
}
Foreach Statement
ILM Proprietary and Confidential - http://www.ilmservice.com
Classes Used to declare reference types Single inheritance from other classes Multiple inheritance from interfaces Class members can include the following
Constants Fields, Methods, Properties, Indexers, Events Operators Constructors, destructors Nested Types
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com
Access Modifiers Public
Members are available to all code Protrected
Members are accessible only from derived classes
Internal Members are accessible only from within the same
assembly
Protected Internal Members are accessible only from derived classes
within the same assembly
Private Members are accessible only from the class itself
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com
Interfaces Define a contract Class that implements an interface must adhere
to its contract Interface members can consists of the following
Methods Properties Indexers Events
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com
Properties public class Button: Control {private string caption;public string Caption {
get
{return caption;
}
set
{caption = value;Repaint();
}
}
}
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com
Indexers public class ListBox: Control {private string[] items;public string this[int index] {
get
{return items[index];
}
set
{items[index] = value;Repaint();
}
}
}
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com
Exception Handlingtry { //try-statement:
block of code
}
catch ( class-type identifieropt ) { //specific-catch-clauses:
block of code
}
catch { //general-catch-clause:
block of code
}
finally { // finally-clause:
block of code
}
OO Programming With C#
ILM Proprietary and Confidential - http://www.ilmservice.com