1 / 18

C# Language Report

C# Language Report. By Trevor Adams. Language History. Developed by Microsoft Principal Software Architect Anders Hejlsberg C# 1.0 – mid 2000 C# 2.0 – 2005 C# 3.0 – Currently Under Development. Implementation. Hybrid Implementation .Net Framework Preprocessor Unsafe Code.

aya
Download Presentation

C# Language Report

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# Language Report By Trevor Adams

  2. Language History • Developed by Microsoft • Principal Software Architect • Anders Hejlsberg • C# 1.0 – mid 2000 • C# 2.0 – 2005 • C# 3.0 – Currently Under Development

  3. Implementation • Hybrid Implementation • .Net Framework • Preprocessor • Unsafe Code

  4. Overall Structure of a Program // A skeleton of a C# program using System; namespace MyNamespace1 { class MyClass1 { } struct MyStruct { } interface IMyInterface { } delegate int MyDelegate(); enum MyEnum { } namespace MyNamespace2 { } class MyClass2 { public static void Main(string[] args) { } } }

  5. Control Structures • Selection Statements • Iterative Statements • Unconditional Branching

  6. Selection Statements selection-statement=> if-statement |switch-statement if (x == y) { //execute block if true} else { //execute block if false} string myString = "hello"; switch (myString) { case "hello": Console.WriteLine("Hello there"); break; case "goodbye": Console.WriteLine(“Good Bye Dude"); break; }

  7. Iterative Statements iteration-statement => while-statement | do-statement | for-statement | foreach-statement using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace ConApp.Demo { class Program { static void Main(string[] args) { ArrayList arrList = new ArrayList(); arrList.Add("First Item"); arrList.Add("Second Item"); arrList.Add("Third Item"); foreach(string myString in arrList){ Console.WriteLine(myString); } Console.ReadLine(); } } }

  8. Unconditional Branching jump-statement => break-statement | continue-statement | goto-statement | return-statement | throw-statement

  9. Data Types • Primitive Data Types • Arrays • Record Types • Union Types • Pointer Types

  10. Primitive Data Types • object - The ultimate base type of all other types • string - String type; a string is a sequence of Unicode characters • sbyte - 8-bit signed integral type • short - 16-bit signed integral type • int - 32-bit signed integral type • long - 64-bit signed integral type l • byte - 8-bit unsigned integral type • ushort - 16-bit unsigned integral type • uint - 32-bit unsigned integral type • ulong - 64-bit unsigned integral type • float - Single-precision floating point type • double - Double-precision floating point type • bool - Boolean type; a bool value is either true or false • char - Character type; a char value is a Unicode character • decimal - Precise decimal type with 28 significant digits

  11. Arrays int[] arr = new int[] {1, 2, 3, 4, 5}; int[,] a2 = new int[,] {{1, 2, 3}, {4, 5, 6}}; int[,,] a3 = new int[10, 20, 30]; int[][] j2 = new int[3][]; j2[0] = new int[] {1, 2, 3}; j2[1] = new int[] {1, 2, 3, 4, 5, 6}; j2[2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};

  12. Record Types struct Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } }

  13. Union Types [StructLayout(LayoutKind.Explicit)] public struct MyUnion { [FieldOffset(0)] public int x; [FieldOffset(0)] public double y; }

  14. Pointer Types using System;class MyClass{ public unsafe void Method() { int x = 10; int y = 20; int *ptr1 = &x; int *ptr2 = &y; Console.WriteLine((int)ptr1); Console.WriteLine((int)ptr2); Console.WriteLine(*ptr1); Console.WriteLine(*ptr2); }}

  15. Sub Programs and Parameter Passing • The way variables are passed is affected by two things: • The data type of the parameter. • What modifiers are present when the parameter is passed.

  16. Value vs. Reference Types • The following types are passed by Value by default: • Struct types • Enumeration types • Numeric types • Integral types • Floating-point types • decimal • bool

  17. Parameter Modifiers • ref – allows a value type to be passed by reference • out – allows a parameter to be passed as an out parameter

  18. Parameter Modifiers class ParameterModifiers { static void Main(string[] args) { int myInt = 9; modifyInt1(myInt); Console.WriteLine(myInt); modifyInt2(ref myInt); Console.WriteLine(myInt); modifyInt3(out myInt); Console.WriteLine(myInt); Console.ReadLine(); } private static void modifyInt1(int myInt) { myInt++; } public static void modifyInt2(ref int myInt) { myInt++; } private static void modifyInt3(out int myInt) { myInt++; } }

More Related