1 / 26

Web Server Programming

Web Server Programming. C#. Content. A Summary on the C # Language. Introduction to C#. Variable Declarations in C#. int x; int x = 5; string s; string s1, s2; object o; object obj = new object(); public string name;. Statements. Response.Redirect("NewPage.aspx"); x = y + 5;

Download Presentation

Web Server Programming

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. Web Server Programming C#

  2. Content • A Summary on the C# Language Muzaffer DOĞAN - Anadolu University

  3. Introduction to C# Muzaffer DOĞAN - Anadolu University

  4. Variable Declarations in C# • int x; • int x = 5; • string s; • string s1, s2; • object o; • object obj = new object(); • public string name; Muzaffer DOĞAN - Anadolu University

  5. Statements • Response.Redirect("NewPage.aspx"); • x = y + 5; • a = b = c = 5; Muzaffer DOĞAN - Anadolu University

  6. Comments • // This is a comment • /* Thisisamultilinecomment*/ Muzaffer DOĞAN - Anadolu University

  7. Arrays • string[] course = new string[3];course[0] = "Web";course[1] = "Server";course[2] = "Programming"; • int[] arr = new int[5]{1, 2, 3, 4, 5}; • int[][] mat = new int[2][3];mat[1][2] = 5; • int [,] mat = new int[3,4];mat[2,3] = 5; • char[] delimeters = new char[]{' ', '\r', '\n'}; Muzaffer DOĞAN - Anadolu University

  8. Indexed Properties • // Creating arrays: • int[] arr = new int[100]; • int[,] mat = new int[50, 100]; • // Accessing array elements: • int x = arr[2]; • arr[0] = 5; • string name = Request.QueryString["name"]; Muzaffer DOĞAN - Anadolu University

  9. Properties • private string m_Username;public string Username { get { return m_Username; } set { m_Username = value; }} Muzaffer DOĞAN - Anadolu University

  10. Properties • public string Name { get { return TextBox1.Text; } set { if (value.StartsWith("m")) { TextBox1.Text = value; } }} Muzaffer DOĞAN - Anadolu University

  11. Automatic Properties • public string Username {get; set;} • A private variable to hold the value of the property is automatically created by the compiler • It can be used after C# 3.0 • You can create this type of properties in Visual Studio by typing prop and pressing TAB key two times Muzaffer DOĞAN - Anadolu University

  12. Why Properties? • Allows read-only and write-only fields • Can validate a field when it is assigned • Interface and implementation of data my differ (i.e., value can be written into a Label control) • Visual Studio IDE can list properties of an object when dot-key is pressed (intellisense) Muzaffer DOĞAN - Anadolu University

  13. Enumerations • // Declare the enumeration:public enum MessageSize { Small = 0, Medium = 1, Large = 2} • // Create a field or property:MessageSize msgSize; • // Assign a value:msgSize = MessageSize.Medium; Muzaffer DOĞAN - Anadolu University

  14. Declaring and Calling Methods • private int Add(int a, int b) { return a + b;} • public void PrintHeader() { Console.WriteLine("This is a header");} • int z = Add(x, y); • PrintHeader(); Muzaffer DOĞAN - Anadolu University

  15. If Statement • if (a == 3) TextBox1.Text = "three"; • if (a == 3) { TextBox1.Text = "three"; Label1.Text = "four";} Muzaffer DOĞAN - Anadolu University

  16. If, Else, Else If • if (a == 1) Label1.Text = "one";else if (a == 2) Label1.Text = "two";else Label1.Text = "other"; Muzaffer DOĞAN - Anadolu University

  17. Case Statement • int num = 5;switch (num) { case 1: Label1.Text = "one"; break; case 2: case 3: Label1.Text = "two or three"; break; default: Label1.Text = "other"; break;} Muzaffer DOĞAN - Anadolu University

  18. Case Statement • string color = "blue"; • switch (color) { case "red": Label1.Text = "Red"; break; case "blue": Label1.Text = "Blue"; break; default: Label1.Text = "Not Red Nor Blue"; break;} Muzaffer DOĞAN - Anadolu University

  19. Case Statement • enum MessageSize {Small, Medium, Large}; • MessageSize msgSize = MessageSize.Small; • switch (msgSize) { case MessageSize.Small: Label1.Text = "S"; break; case MessageSize.Medium: Label1.Text = "M"; break; case MessageSize.Large: Label1.Text = "L"; break; default: Label1.Text = "---"; break;} Muzaffer DOĞAN - Anadolu University

  20. For Loop • for (int i = 0; i < 10; i++) single_statement(); • for (int i = 0; j < 10; k %= 2) { statement1(); statement2();} Muzaffer DOĞAN - Anadolu University

  21. Foreach Loop • int[] arr = newint[]{5, 7, 9, 10, 3}; • foreach (int number in arr){ Label1.Text += number.ToString() + "<br/>";} Muzaffer DOĞAN - Anadolu University

  22. While Loop • int n = 5; • while (n > 0){ Label1.Text += n.ToString() + "\r\n"; n--;} Muzaffer DOĞAN - Anadolu University

  23. Do..While Loop • int grade = 0;do{ grade += DoNextHomework();} while (grade < 100); Muzaffer DOĞAN - Anadolu University

  24. Exception Handling • try { // Code that throws exception} catch (OverflowException e) { // Catch a specific exception} catch (Exception e) { // Catch the generic exceptions} finally { // Execute some cleanup code} Muzaffer DOĞAN - Anadolu University

  25. String Operations • string s1 = "Web"; • string s2 = "Programming"; • string s3 = s1 + " " + s2; • s3 += " (Server Side)"; • // Use StringBuilder class for performance:StringBuilder s3 = new StringBuilder();s3.Append("Web");s3.Append(" Programming"); Muzaffer DOĞAN - Anadolu University

  26. Type Casting and Conversion • double d = 5.4321; • int n = (int)d; • string s = n.ToString(); • int n = int.Parse("54321"); • double d = double.Parse("54.321"); Muzaffer DOĞAN - Anadolu University

More Related