Web Server Programming
-
Upload
chaim-freeman -
Category
Documents
-
view
15 -
download
2
description
Transcript of Web Server Programming
![Page 1: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/1.jpg)
Web Server ProgrammingC#
![Page 2: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/2.jpg)
ContentA Summary on the C# Language
Muzaffer DOĞAN - Anadolu University 2
![Page 3: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/3.jpg)
Introduction to C#
Muzaffer DOĞAN - Anadolu University 3
![Page 4: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/4.jpg)
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 4
![Page 5: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/5.jpg)
StatementsResponse.Redirect("NewPage.aspx");x = y + 5;a = b = c = 5;
Muzaffer DOĞAN - Anadolu University 5
![Page 6: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/6.jpg)
Comments// This is a comment/* Thisisamultilinecomment*/
Muzaffer DOĞAN - Anadolu University 6
![Page 7: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/7.jpg)
Arraysstring[] 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 7
![Page 8: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/8.jpg)
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 8
![Page 9: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/9.jpg)
Propertiesprivate string m_Username;
public string Username { get { return m_Username; } set { m_Username = value; }}
Muzaffer DOĞAN - Anadolu University 9
![Page 10: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/10.jpg)
Propertiespublic string Name { get { return TextBox1.Text; } set { if (value.StartsWith("m")) { TextBox1.Text = value; } }}
Muzaffer DOĞAN - Anadolu University 10
![Page 11: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/11.jpg)
Automatic Propertiespublic 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.0You can create this type of properties in
Visual Studio by typing prop and pressing TAB key two times
Muzaffer DOĞAN - Anadolu University 11
![Page 12: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/12.jpg)
Why Properties?Allows read-only and write-only fieldsCan validate a field when it is assignedInterface 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 12
![Page 13: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/13.jpg)
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 13
![Page 14: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/14.jpg)
Declaring and Calling Methodsprivate 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 14
![Page 15: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/15.jpg)
If Statementif (a == 3) TextBox1.Text = "three";
if (a == 3){ TextBox1.Text = "three"; Label1.Text = "four";}
Muzaffer DOĞAN - Anadolu University 15
![Page 16: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/16.jpg)
If, Else, Else Ifif (a == 1) Label1.Text = "one";else if (a == 2) Label1.Text = "two";else Label1.Text = "other";
Muzaffer DOĞAN - Anadolu University 16
![Page 17: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/17.jpg)
Case Statementint 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 17
![Page 18: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/18.jpg)
Case Statementstring 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 18
![Page 19: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/19.jpg)
Case Statementenum 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 19
![Page 20: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/20.jpg)
For Loopfor (int i = 0; i < 10; i++) single_statement();
for (int i = 0; j < 10; k %= 2) { statement1(); statement2();}
Muzaffer DOĞAN - Anadolu University 20
![Page 21: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/21.jpg)
Foreach Loopint[] arr = new int[]{5, 7, 9, 10, 3};
foreach (int number in arr){ Label1.Text += number.ToString() + "<br/>";}
Muzaffer DOĞAN - Anadolu University 21
![Page 22: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/22.jpg)
While Loopint n = 5;while (n > 0){ Label1.Text += n.ToString() + "\r\n"; n--;}
Muzaffer DOĞAN - Anadolu University 22
![Page 23: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/23.jpg)
Do..While Loopint grade = 0;do{ grade += DoNextHomework();} while (grade < 100);
Muzaffer DOĞAN - Anadolu University 23
![Page 24: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/24.jpg)
Exception Handlingtry { // 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 24
![Page 25: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/25.jpg)
String Operationsstring 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 25
![Page 26: Web Server Programming](https://reader037.fdocuments.us/reader037/viewer/2022110102/568135a6550346895d9d1739/html5/thumbnails/26.jpg)
Type Casting and Conversiondouble 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 26