Understanding C# and .NET Programming Basics

c c net n.w
1 / 37
Embed
Share

Explore the fundamentals of C# and .NET programming, including integral types, floating-point types, operators, and essential concepts for developing applications. Discover the structure of Visual Studio, key elements like Console Applications and Windows Forms, and important programming techniques such as case sensitivity. Gain insights into data types, precision, and common coding practices in C# and .NET.

  • C#
  • .NET
  • Visual Studio
  • Programming Basics
  • Data Types

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. C#,C#.Net ) ( : 1

  2. ( 15 + ( ) 15 + ] + ( 65 )% ---------------- )% )% ( ( 5 )% [ ( 5 )% 2

  3. :Visual Stadio NetFarmework Cts Cts Bcl Bcl . .NetFarmework Jit Jit :Console Application - - - - - ( - - - - - - ) : Windows Forms Application Rich text Group Box message box Radio Button NumericUpDown TextBox ... button Check Box CheckedListBox ComboBox Timer Progress Bar LinkLable PictureBox box List Box 3

  4. . Case Sensitive C# : < Letter | _ > < Letter | Digit | _ > . . . < Letter | Digit | _ > int i , j=12 ; int int 4 float f=12.5F ; float float 4 double double double d=12.5 ; 8 char c = m ; char char 2 string n= Book_2 ; string string bool a=true; bool bool 1 4

  5. Integral Types Table ( ) Type Range Size -128 to 127 Signed 8-bit integer SByte(sbyte) 0 to 255 Unsigned 8-bit integer Byte(byte) U+0000 to U+ffff Unicode 16-bit character Char(char) -32,768 to 32,767 Signed 16-bit integer Int16(short) 0 to 65,535 Unsigned 16-bit integer UInt16(ushort) -2,147,483,648 to 2,147,483,647 Signed 32-bit integer Int32(int) 0 to 4,294,967,295 Unsigned 32-bit integer UInt32(uint) -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Signed 64-bit integer Int64(long) 0 to 18,446,744,073,709,551,615 Unsigned 64-bit integer UInt64(ulong) Floating-Point Types Table ( ) Range Type Size Precision 7 digits 1.5e 45 to 3.4e38 32-bit float(Single) 15-16 digits Double(double) 5.0e 324 to 1.7e308 64-bit eg. : short i =10 , j ; double e= 2.71828182845905 ; 5

  6. : : 12 , 0x12 , 0X12 : 12.6 , 3e+5 , 3e5 , 3.2e-4 : # 9 A : a_1@yahoo.com a123 Computer : true , false : : ) ( const float pi = 3.14F ; const int id = 20 ; /* */ ( Comment ) // : 6

  7. ( ( OPERATORS ) : OPERATORS ) : ( + , - , * , / , % ) : 5 / 2 = 2 , 5.0 / 2 = 5 / 2.0 = 2.5 , 9.5 % 2 = 1.5, (int)9.5%2 = 1 ( - , + + , - - , sizeof ) : + + n ; // n = n + 1 ; n + + ; ( < , > , <= , >= , = = , != , && , || , ! ) : ( = , += , -= , *= , /= , %= ) : s += n ; // s = s + n ; x = y = 3 ; max = ( a > b ) ? a : b; ( ?: ) : != , = = , - + / , * || ( ( : && 7

  8. CONSOLE. CONSOLE.WRITELINE WRITELINE : CONSOLE. CONSOLE.WRITE WRITE Console.Write("abc"); Console.WriteLine("def"); abcdef abc def Sum Of a, b is 15 Sum Of 5, 10 is 15 19.8 123,456.34 Console.WriteLine("abc"); Console.WriteLine("def"); int a = 5, b = 10; Console.WriteLine("Sum Of a,b is {0}", a + b); Console.WriteLine("Sum Of {0},{1} is {2}", a, b, a + b); double d = 19.76, e = 123456.344; Console.WriteLine(d.ToString("00.0")); Console.WriteLine(e.ToString("0,0.00")); Console.ReadKey(); 8

  9. int a = 27; Console.WriteLine(a.ToString("X")); 1B 1.230000E+006 1.230E+6 12.300E+5 a= 27 b= 1230000 double d = 1230000; Console.WriteLine(d.ToString("E")); Console.WriteLine(d.ToString("0.000E+0")); Console.WriteLine(d.ToString("00.000E+0")); Console.WriteLine("a=\t{0}\n\ab=\t{1}", a, d); Console.ReadKey(); \a = Alarm , \b = Backspace , \n = New Line , \t = Tab 9

  10. CONSOLE.READLINE : string s; s=Console.ReadLine(); int i; i=Convert.ToInt32(s); Console.WriteLine(i + i); i = Int32.Parse(s); Console.WriteLine(i + i); double d = Convert.ToDouble (Console.ReadLine()); //double d = double.Parse(Console.ReadLine()); Console.WriteLine(d); 10

  11. ) ( MATH MATH : : 1- Math.Abs 13- Log10 10 ) ( ( ) 15- Round 16- Sign 17- Sin 19- Sqrt 2- Acos 3- Asin 4- Atan 5- BigMul 6- Ceiling 14- Pow 18- Sinh 7- Floor 8- Cos 20- Tan 21- Tanh 22- Truncate 9- Cosh 10- DivRem 23- E ) 2.718 3.14 ) ( ( 11- Exp 12- Log 24- PI 11

  12. : : ) : 1 - x = 2 ; y = Math.Pow ( x , 2 ) + 1 ; : 2 - + + x ; x - - ; : 3 - Console.Clear(); Console.WriteLine("Test"); { } ) ) : ) ( ( : ) 12

  13. IF IF : Syntax: if ( exp ) statement1 ; [ else statement 2 ; ] eg.1: if ( a > b ) Console.WriteLine(a); eg.2: if (a < b) Console.WriteLine(a); else Console.WriteLine(b); if (a < b) Console.WriteLine(a); else Console.WriteLine(b); eg.3: if (a < b) { int t = a; a = b; b = t; } eg.4: if (a >= 10 && a < 100) Console.WriteLine("Two Digits"); 13

  14. : string str1, str2; str1 = Console.ReadLine(); str2 = Console.ReadLine(); if (str1 == str2) //if (str1.CompareTo(str2)==0) Console.WriteLine("Equal"); if (str1 != str2) //if (str1.CompareTo(str2)!=0) Console.WriteLine("Not Equal"); //if (str1 < str2) if (str1.CompareTo(str2) < 0) //if (string.Compare(str1, str2) < 0) Console.WriteLine("{0} Less Than {1}", str1, str2); if (string.Compare(str1, str2, true) == 0) //Ignore Case Console.WriteLine("{0} Equal {1}", str1, str2); 14

  15. SWITCH : SWITCH : Syntax: switch ( exp ) statement ( exp ) eg. : switch (a) { case 0: Console.WriteLine ("Zero"); break; case 1: Console.WriteLine("One"); break; case 2: case 3: Console.WriteLine("Two or Three"); break; default: Console.WriteLine("Greater Than or Equal Four "); break; } 15

  16. DO ... DO ... WHILE : WHILE : WHILE WHILE Syntax Syntax: while ( exp ) statement ; : while ( exp ) statement ; do statement while ( exp ) ; do statement while ( exp ) ; eg. eg.1 1: int x = : int x = 1 1; ; while (x <= while (x <= 10 10) ) { { Console.WriteLine(x); Console.WriteLine(x); x++; x++; } } //while (x <= //while (x <= 10 eg. eg.3 3: int x = : int x = 0 0 ; ; while ( x < while ( x < 10 10 ) ) Console.WriteLine( // do // do Console.WriteLine Console.WriteLine(++x ) ; while ( x < eg.2: int x = 1 ; do { Console.WriteLine(x); x++; } while (x <= 10); 10) Console.WriteLine(x++); ) Console.WriteLine(x++); Console.WriteLine(++x ) ; (++x ) ; while ( x < 10 ++x ) ; 10 ) ; ) ; 16

  17. : int r, c; r = 1; while (r <= 10) { c = 1; while (c <= r) { 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 Console.Write("{0} ",c); c++; } r++; Console.Write("\n"); //Console.WriteLine(); } 17

  18. FOR FOR : : Syntax: for ( [exp1] ; [exp2] ; [exp3] ) statement ; eg.1: int x ; for ( x = 1 ; x <= 10 ; x ++ ) Console.WriteLine (x) ; int x = 1; for (; x <= 10; ) Console.WriteLine(x++); int x = 1; for (; ; ) { Console.WriteLine(x++); if (x > 10) break; // } int x = 1; for (; x <= 10; x++) Console.WriteLine(x); 18

  19. CONTINUE CONTINUE : : eg.1: int s = 0, n; for (int i = 1; i <= 10; i++) { n = Convert.ToInt32(Console.ReadLine()); if (n < 0) continue; s += n; } Console.WriteLine(s); eg.2: int s = 0, i = 1, n; while (i <= 10) { n = Convert.ToInt32(Console.ReadLine()); i++; if (n < 0) continue; s += n; } Console.WriteLine(s); 19

  20. GOTO GOTO : : eg.1: int x = 1; L1: Console.WriteLine(x); x++; if (x <= 10) goto L1; Console.ReadKey(); Identifier 20

  21. : : type[ ] Array_name ; int[ ] x = new int[3]; char[ ] s = new char[10]; double[ , ] m = new double[30, 4]; int[] m = new int[5]; for (int i = 0; i < 5; i++) m[i] = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < 5; i++) Console.WriteLine(m[i]); 21

  22. int [,] a = new float [ int [,] a = new float [2 2, , 3 3]; ]; for (int i = for (int i = 0 0; i < ; i < 2 2; i++) for (int j = for (int j = 0 0; j < a[i,j] = Convert.ToInt a[i,j] = Convert.ToInt32 for (int i = for (int i = 0 0; i < ; i < 2 2; i++) for (int j = for (int j = 0 0; j < Console.WriteLine(a[i,j]); Console.WriteLine(a[i,j]); ; i++) ; j++) ; j < 3 3; j++) 32(Console.ReadLine()); (Console.ReadLine()); ; i++) ; j++) ; j < 3 3; j++) int i, j, t; int i, j, t; int[] m = new int[ int[] m = new int[5 5]; ]; for (i = for (i = 0 0; i < ; i < 5 5; i++) m[i] = Convert.ToInt m[i] = Convert.ToInt32 for (i = for (i = 0 0; i < ; i < 4 4; i++) for (j = i + for (j = i + 1 1; j < if (m[i] > m[j]) if (m[i] > m[j]) { { t = m[i]; m[i] = m[j]; m[j] = t; t = m[i]; m[i] = m[j]; m[j] = t; } } ; i++) 32(Console.ReadLine()); (Console.ReadLine()); ; i++) ; j < 5 5; j++) ; j++) : if (string.Compare(m[i],m[j])>0) 22

  23. : : int[ ] a = new int[5]; //{0, 0, 0, 0, 0 } int[ ] b = new int[ ] { 1, 2, 3, 4, 5 }; //{1, 2, 3, 4, 5 } int[ ] c = { 1, 2, 3, 4, 5 }; int[ , ] m = { { 1, 2, 3 }, { 4, 5, 6 } }; int[ , ] n = { { 1, 2, 3 }, { 4, 5, 6 } }; 23

  24. : : ( (DEFINE FUNCTION DEFINE FUNCTION) ) . Procedural Modular ) ( . . static type Function_Name(type Arg1, type Arg2, ) { Statements } 24

  25. static float fact ( int x) { float f=1; for ( int i=2; i<=x; i++) f*=i; return ( f ); } static int sum(int x, int y) { int s = x + y ; return ( s ); } static char first_rate ( int n ) { char ans= y ; for ( int i=2; i<n ; i++ ) if ( n%i = = 0 ) ans= n ; return ( ans ); } . . void void main ( ) : 25

  26. : ( : (RECURSIVE) RECURSIVE) Recursion . : 5! = 5 * 4! , 4! = 4 * 3! , ... , 1!=1 * 0! , 0!=1 : 5 * 6 = 6 + 4 * 6 , 4 * 6 = 6 + 3 * 6 , ... , 0 * 6 = 0 : 34= 3 * 33, 33= 3 * 32, ... , 31= 3 * 30, 30= 1 26

  27. static double fact(int x) { if (x<=1) return(1); else return(x*fact(x-1)); } static long mul(int x , int y) { if (x==0) return(0); else return(y+mul(x-1,y)); } Static double pow(int x , int y) { if (y==0) return(1); else return(x*pow(x,y-1)); } 27

  28. : static void test(int x) { x++; Console.WriteLine(x); } static void Main(string[ ] args) { int a = 10; test(a); Console.WriteLine(a); Console.ReadKey(); } static void test(ref int x) { x++; Console.WriteLine(x); } static void Main(string[ ] args) { int a = 10; test(ref a); Console.WriteLine(a); Console.ReadKey(); } Call By Reference Call By Value 11 11 10 10 11 11 11 11 28

  29. : : . . static float static float max_ar { { float m = n[ float m = n[0 0]; ]; for (int for (int i i = = 1 1; ; i i < < n.Length if (n[ if (n[i i] > m) m = n[ ] > m) m = n[i i]; ]; return (m); return (m); } } max_ar( float[ ] n ) ( float[ ] n ) n.Length ; ; i i++) ++) 29

  30. : : . . static float static float max_ar { { float m = n[ float m = n[0 0]; ]; for (int for (int i i = = 1 1; ; i i < < n.Length if (n[ if (n[i i] > m) m = n[ ] > m) m = n[i i]; ]; return (m); return (m); } } max_ar( float[ ] n ) ( float[ ] n ) n.Length ; ; i i++) ++) 30

  31. static void Main(string[ ] args) { float[ ] n = new float[ ] { 1, 4, 12, 3, 2 }; sort_ar(n); for (int i = 0; i < n.Length; i++) Console.WriteLine(n[i]); Console.ReadKey(); } static void sort_ar(float[ ] a) { for (int i = 1; i < a.Length; i++) for (int j = 0; j < a.Length - i; j++) if (a[j] > a[j + 1]) { float m = a[j]; a[j] = a[j + 1]; a[j + 1] = m; } } 31

  32. : STRUCTURE ) struct student { public string name; public float avg; public int id; } static void Main(string[ ] args) { student x; x.avg = 10; Console.WriteLine(x.avg); ( ( STRUCTURE ) name id avg student[ ] c = new student[30]; c[0].name = "ali"; Console.WriteLine(c[0].name); Console.ReadKey(); } 32

  33. : struct date { public short y; public byte m, d; } struct student { public string name; public float avg; public int id; public date birth_date; } student s; s.name = "ali"; s.birth_date.y = 1988; Console.WriteLine(s.birth_date.y); 33

  34. : CONSOLE.READKEY ConsoleKeyInfo c; c = Console.ReadKey(); //if Alt+b is pressed Console.WriteLine(c.KeyChar); //b Console.WriteLine(c.Key); //B Console.WriteLine(c.Modifiers); //Alt Console.ReadKey(); c = Console.ReadKey(true); //Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false. 34

  35. : : Random r=new Random(); Console.WriteLine(r.Next()); Console.WriteLine(r.Next(900)); Console.WriteLine(r.NextDouble()); // // 900 // 35

  36. WINDOWS FORMS APPLICATION 36

  37. WINDOWS 37

Related


More Related Content