ilm proprietary and confidential -

16
ILM Proprietary and Confidential - http://www.ilmservice.com

Upload: job-may

Post on 03-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ILM Proprietary and Confidential -

ILM Proprietary and Confidential - http://www.ilmservice.com

Page 2: ILM Proprietary and Confidential -

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

Page 3: ILM Proprietary and Confidential -

using System;class Hello{ static void Main()

{ Console.WriteLine("Hello, world"); }}

A Simple C# Program

ILM Proprietary and Confidential - http://www.ilmservice.com

Page 4: ILM Proprietary and Confidential -

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

Page 5: ILM Proprietary and Confidential -

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

Page 6: ILM Proprietary and Confidential -

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

Page 7: ILM Proprietary and Confidential -

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

Page 8: ILM Proprietary and Confidential -

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

Page 9: ILM Proprietary and Confidential -

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

Page 10: ILM Proprietary and Confidential -

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

Page 11: ILM Proprietary and Confidential -

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

Page 12: ILM Proprietary and Confidential -

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

Page 13: ILM Proprietary and Confidential -

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

Page 14: ILM Proprietary and Confidential -

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

Page 15: ILM Proprietary and Confidential -

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

Page 16: ILM Proprietary and Confidential -

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