123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
using System; using System.Text; namespace Mains { class Program { static int Main(string[] args) { //--- reading args of main for (int i = 0; i < args.Length; i++) { Console.WriteLine("Arg: {0}", args[i]); } // or foreach (string arg in args) Console.WriteLine("Arg: {0},{1}", arg, 123); //or System.Enviroment Console.WriteLine("True {0}", bool.TrueString); //--- char char myChar = 'a'; if (char.IsDigit(myChar)) { Console.WriteLine("digit"); } //--- parse from string bool b = bool.Parse("true"); //--- dateTime DateTime dt = new DateTime(2017, 08, 20); Console.WriteLine(dt.DayOfWeek); string s = "someString"; if (s.Contains("some")) {/*do something*/ } Console.Write("beep\a\n\r"); Console.WriteLine("beep\a\n\r"); //--- verabtim strings Console.Write(@"some\Dir\"); // will // string builder using System.Text StringBuilder sb = new StringBuilder(); sb.Append("\n"); sb.AppendLine("Line1"); sb.AppendLine("Line2"); sb.AppendLine("Line3"); Console.WriteLine(sb.ToString()); // Convert byte myByte = 0; int myInt = 200; myByte = Convert.ToByte(myInt); Console.WriteLine("Value of my Byte {0}", myByte); //----- narrowing and checked directive short myShort; int myInt1 = 100000000; // myShort = myInt1; // Severity Code Description Project File Line Suppression State //Error CS0266 Cannot implicitly convert type 'int' to 'short'.An explicit conversion exists (are you missing a cast?) Mains C:\C#\MyC#StudyProjects\07_DifferentMains\Mains\Mains\Program.cs 64 Active try { checked { myShort = (short)myInt1; } } //{ checked { myShort = Convert.ToUInt16(myInt1); } } catch (OverflowException ex) { Console.WriteLine(ex.Message); } //----- var directive var myInt2 = 0; var myBool = true; var myString = "string"; Console.WriteLine(myInt2.GetType().Name); Console.WriteLine(myBool.GetType().Name); Console.WriteLine(myString.GetType().Name); // for for (var i = 0; i < 10; i++) { /*do something*/} //foreach int[] intArray = { 0, 1, 2, 3 }; foreach (var i in intArray) { /*do something*/} //while var j = 0; while (j < 10) { j++; } //do while do { j++; } while (j < 10); // if else if (j < 10) { } else if (j == 10) { } else if (j == 1) { }; // and or not && || ! if ( (j<=10) && (j>=11) ){ } if ((j <= 10) || (j >= 12)) { } if ((j != 12) || (j >= 12)) { } //switch var n = 12; switch (n) { case 1: { };break; case 2: { };break; default: { };break; } //---------- Console.ReadLine(); return -1; } } } |