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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
| using Microsoft.Win32; using System; using System.Threading.Channels;
namespace HelloWorldApplication { class Recttangle { double length; double width; public void Acceptdetails() { length = 4.5; width = 3.5; } public double GetArea() { return length * width; } public void Display() { Console.WriteLine("Length:{0}", length); Console.WriteLine("Width:{0}", width); Console.WriteLine("Area:{0}", GetArea()); } } class Helloworld { static void Main(string[] args) { Console.WriteLine("你好,C#!"); Console.WriteLine("你好,Visual Studio!"); Recttangle r = new Recttangle(); r.Acceptdetails(); r.Display();
bool BoolOne = true; byte ByteOne = 6, ByteTwo = 5; char CharOne = 'a'; char CharTwo = 'b'; decimal DecimalOne = 0.0M; double DoubleOne = 111.111; float FloatOne = 111.111F; int IntOne = 111; long LongOne = 111; sbyte SbyleOne = 127; short ShortOne = 3456; uint UintOne = 111; ulong ulongOne = 222; ushort ushortOne = 333;
Console.WriteLine("这是布尔类型:"+BoolOne); Console.WriteLine("这是byte类型:"+ByteOne+ByteTwo); Console.WriteLine("这是字符类型:"+CharOne+CharTwo); Console.WriteLine("这是decimal类型:"+DecimalOne); Console.WriteLine("这是Double类型:"+DoubleOne); Console.WriteLine("这是Folat类型:"+FloatOne); Console.WriteLine("这是Int类型:"+IntOne); Console.WriteLine("这是long类型:"+LongOne); Console.WriteLine("这是sbyte类型:"+SbyleOne); Console.WriteLine("这是short类型:"+ShortOne); Console.WriteLine("这是unit类型:"+UintOne); Console.WriteLine("这是ulong类型:"+ulongOne); Console.WriteLine("这是ushort类型:"+ushortOne); Console.WriteLine("\n");
double DoubleThree = 3.3333; int NumberOne; int NumberTwo; int NumberThree;
NumberOne=111; NumberTwo=222; NumberThree=333;
Console.WriteLine("随便输出几个数字:"+NumberOne+NumberTwo+NumberThree); Console.WriteLine("随便输出一个强制类型转换的数字:"+(int)DoubleThree);
Console.WriteLine("输出字符串{0}", "啊输出字符串"); Console.WriteLine("浅记一下逻辑运算符:");
bool BoolTwo = false; bool BoolThree = false; bool BoolFour = false;
if (NumberThree>NumberTwo) { BoolTwo = true; } if (NumberTwo>NumberOne) { BoolFour = true; } Console.WriteLine(BoolFour&&BoolTwo); Console.WriteLine(BoolFour&&BoolThree); Console.WriteLine(BoolFour||BoolThree); Console.WriteLine(!(BoolTwo && BoolThree));
int BitwiseNumberOne = 60; int BitwiseNumberTwo = 13;
Console.WriteLine(BitwiseNumberOne&BitwiseNumberTwo); Console.WriteLine(BitwiseNumberOne|BitwiseNumberTwo);
int NumberFive = 1; switch (NumberFive) { case 1: Console.WriteLine("这个数字是1"); break; case 2: Console.WriteLine("传透过来了。"); break; case 3: Console.WriteLine("但是问题不大哦"); break; default: Console.WriteLine("233333"); break; }
switch (NumberFive) { case 0: Console.WriteLine("还有吗"); break; case 1:
Console.WriteLine("哈哈哈"); break; } int WhileNmuber = 3; while (WhileNmuber>0) { WhileNmuber--; Console.WriteLine("减减"); } for (int i = 0; i<3;) { i++; Console.WriteLine("原来是这样!"); } int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 }; foreach (int element in fibarray)
{ System.Console.WriteLine(element); } int count = 0; foreach (int element in fibarray) { count += 1; System.Console.WriteLine("Element #{0}: {1}:{2}", count, element, "我去", "2333"); } do { Console.WriteLine("欸嘿我先执行一次辣~"); } while (0>1);
NumberManipulator n = new NumberManipulator(); Console.WriteLine("6 的阶乘是: {0}", n.factorial(6));
int NmubernullOne; int? NmubernullTwo; Console.WriteLine();
double? num1 = null; double? num2 = 3.14157; double? num3 = new double?(); num3 = num1 ?? num2; Console.WriteLine(num3); Console.WriteLine(num1 ?? num2);
double[] balanceOne; double[] balance = new double[10]; balance[0] = 4500.0;
double[] balanceThree = { 2340.0, 4523.69, 3421.0 };
int[] marksOne = new int[5] { 99, 98, 92, 97, 95 };
int[] marksTwo = new int[] { 99, 98, 92, 97, 95 };
int[] marksThree = new int[] { 99, 98, 92, 97, 95 }; int[] score = marksThree;
String StringOne; string stringOne;
Console.ReadKey(); }
enum EnmuOne { One, Two, Three, Four }; int x = (int)EnmuOne.One; int y = (int)EnmuOne.Two; }
}
class NumberManipulator { public int factorial(int num) { int result;
if (num == 1) { return 1; } else { result = factorial(num - 1) * num; return result; } } }
|