C Cody Driskill Overview Originally based on Java

C# Cody Driskill

Overview • Originally based on Java • Premier language for working in windows environments

Datatypes • Strongly Typed • Mixed datatype assignment • Allows “null” values • Unsafe keyword

Generics • Public class Generic. List<T> { void Add(T input) {} } class Test. List { private class Example{} static void Main() { Generic. List<int> l 1 = new Generic. List<int>(); Generic. List<string> l 2 = new Generic. List<string>(); Generic. List<Example> l 3 = new Generic. List<Example>(); }

Scoping • Lexical scoping class A { int x; void Ex() { x = 10; for(whatever) { int x = whatever; } } } class B { int x; void Ex() { int x; x = 10; for(whatever) { x = whatever; } } }

Control Structures • for(int x = 5; x < 8; x +2) • foreach(int x in array) • while(Console. Read. Line()) • do{ something} while (Console. Read. Line()); • if (test) { do this } else { do this } • Switch (test) { case 1: do this; case 2: do this; default: do this; }
![Subprograms class Program { static void Main(string[] ex) // { Example(“TEST!”); } static int Subprograms class Program { static void Main(string[] ex) // { Example(“TEST!”); } static int](http://slidetodoc.com/presentation_image_h2/7f7be573e91b581865a5d657d385789b/image-7.jpg)
Subprograms class Program { static void Main(string[] ex) // { Example(“TEST!”); } static int Adding(int a) // I’m a Function! { int c = a + a; return c; } private static void Example(string b) // I’m a Subprogram! { Console. Write. Line("This is an Example. " + b); int x = Adding(5); Console. Write. Line(“ 5 + 5 = “ + x. To. String()); } }

Concurrency • Threading • Actor Threads - No paramaters -manually started or aborted • Server Threads

Event Handling class Example { public event Event. Handler This. Is. AProblem; protected virtual void On. This. Is. AProblem(Event. Args e) { Event. Handler handler = On. This. Is. AProblem; if (handler != null) { handler(this, e); } } //rest of class code here }
![Exception Handling int Example(int[] array, int index) { try { return array[index]; } catch(System. Exception Handling int Example(int[] array, int index) { try { return array[index]; } catch(System.](http://slidetodoc.com/presentation_image_h2/7f7be573e91b581865a5d657d385789b/image-10.jpg)
Exception Handling int Example(int[] array, int index) { try { return array[index]; } catch(System. Index. Out. Of. Range. Exception e) { throw new System. Argument. Out. Of. Range. Exception( "Index is out of range of the array. "); } }

Resources • msdn. microsoft. com !!!!
- Slides: 11