(02) c sharp_tutorial
Upcoming SlideShare
Loading in...5
×
 

(02) c sharp_tutorial

on

  • 369 views

 

Statistics

Views

Total Views
369
Views on SlideShare
369
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

(02) c sharp_tutorial (02) c sharp_tutorial Presentation Transcript

  • C# Tutorial Jonas Tan [email_address]
  • Reference
    • MSDN The C# Language
      • http://msdn.microsoft.com/vcsharp/programming/language/
  • Hello World!
    • using System;
    • class Form1
    • {
    • private System.Windows.Forms.TextBox textBox1;
    • //Constructor
    • public Form1() {
    • textbox1 = “Hello world!";
    • }
    • //Start the program
    • static void Main() {
    • Application.Run( new Form1() );
    • }
    • }
    View slide
  • Type System
    • Value Types:
      • byte b = 120 (8-bit)
      • char c = ‘a’; (16-bit Unicode)
      • int i=7; (32-bit)
      • long l = 88; (64-bit)
      • string s = “a string”; (set of Unicode characters)
    • Reference Types (arrays)
      • string[] s = new string[10];
      • int[] i = new int[5];
      • char[] c = new char[16];
      • byte[] b = new byte[22];
    View slide
  • Indexers
    • string s = “this is a string”;
    • char ch = s[3];
    • s[6] = ‘x’; //Error! Read Only.
    • int[] i = new int[] {2, 4, 6, 8, 10};
    • int b = i[2];
    • i[3] = 98;
  • Basic Type casting
    • int (32-bit) to long (64-bit)
          • int a = 537;
          • long b = 6473291;
          • b = (long)a;
    • char(16-bit) to int(32-bit)
          • char c = ‘x’;
          • int d = 8;
          • d = (int)c;
    • Dangerous Casting
          • cast int to uint (possible sign error)
          • long to short (possible overflow)
  • Advanced Type Casting
    • int to string
      • int a = 3;
      • string s1 = a.ToString();
    • char array to string
        • char [ ] b2 = new char[3] {‘a’, ‘c’, ‘e’, ‘g’, ‘h’};
        • String s2 = new string(b2);
    • string to int
        • sting s3 = “564”;
        • int c = int.Parse(s3);
    • string to byte array
      • byte[ ] buf1 = Encoding.Unicode.GetBytes(s3);
    • string to char array
      • char [ ] buf2 = s3.ToCharArray();
  • Operators
    • +, -, *, /, %
    • ++, --
    • ==, !=, <, >, <=, >=
    • &, |, ^, ~, !
    • true, false
  • Shift Operation
    • Use two unsigned integers to simulate a unsigned long integer
        • ulong ul = 73654823; //64-bit
        • uint a[2] = new uint[]{0,0}; //2 32-bit unsigned integers
        • a[0] = (uint) ul;
        • a[1] = (uint) ul >> 32;
  • if and while statements
    • if( x>3 && x<8 )
    • {
    • }
    • while( i>2 )
    • {
    • }
    • for( int i=0; i<x; ++i )
    • {
    • }