Title: Microsoft 'NET Runtime
1C Preview
ILM Proprietary and Confidential -
http//www.ilmservice.com
2C Features
- Native support for core .NET framework
- Supports traditional OO concepts such as
- Inheritance
- Polymorphism
- Operator overloading
- C/C like syntax
- No more global variables
ILM Proprietary and Confidential -
http//www.ilmservice.com
3A Simple C Program
- using System
- class Hello static void Main()
- Console.WriteLine("Hello, world")
ILM Proprietary and Confidential -
http//www.ilmservice.com
4Arrays
- 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 int10, 20, 30 -
-
-
ILM Proprietary and Confidential -
http//www.ilmservice.com
5If Statement
- using System
- class Test
- static void Main(string args)
- if (args.Length 0) Console.WriteLine("No
arguments were provided") else Console.WriteLi
ne("Arguments were provided") -
-
ILM Proprietary and Confidential -
http//www.ilmservice.com
6Switch Statement
- 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
ILM Proprietary and Confidential -
http//www.ilmservice.com
7While Statement
- using System
- class Test
- static int Find(int value, int arr)
- int i 0 while (arri ! value)
- if (i gt arr.Length) throw new
ArgumentException() return i -
-
ILM Proprietary and Confidential -
http//www.ilmservice.com
8Do Statement
- using System
- class Test
- static void Main()
- string s
- do
- s Console.ReadLine() while
(s ! "Exit")
ILM Proprietary and Confidential -
http//www.ilmservice.com
9For Statement
- using System
- class Test
- static void Main()
- for (int i 0 i lt 10 i) Console.Write
Line(i)
ILM Proprietary and Confidential -
http//www.ilmservice.com
10Foreach Statement
- using System
- using System.Collections
- class Test
- static void WriteList(ArrayList list)
- foreach (object o in list)
Console.WriteLine(o) -
ILM Proprietary and Confidential -
http//www.ilmservice.com
11OO Programming With C
- 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
ILM Proprietary and Confidential -
http//www.ilmservice.com
12OO Programming With C
- 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
ILM Proprietary and Confidential -
http//www.ilmservice.com
13OO Programming With C
- 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
ILM Proprietary and Confidential -
http//www.ilmservice.com
14OO Programming With C
- Properties
- public class Button Control private string
caption - public string Caption get
- return caption
- set
- caption value Repaint()
-
ILM Proprietary and Confidential -
http//www.ilmservice.com
15OO Programming With C
- Indexers
- public class ListBox Control
- private string items
- public string thisint index get
- return itemsindex
- set
- itemsindex value Repaint()
-
-
ILM Proprietary and Confidential -
http//www.ilmservice.com
16OO Programming With C
- Exception Handling
- try //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
-
ILM Proprietary and Confidential -
http//www.ilmservice.com