visual programming lecture 2

35
Визуаль Програмчлал 1 Лекц 2 ОУУБИС ХМТ-ийн тэнхим Багш Д.Ганцоож

Upload: donald-g-hub

Post on 06-Jan-2017

140 views

Category:

Education


3 download

TRANSCRIPT

1

1 2 - .

C# C#

C# C# .NET C# , C# ++ , , . UNICODE .

C# Using . , . .C# Main() . . static M .

C# :static void Main() {}static void Main(string[] args) {..}static int Main() {.}Static int Main(string[] args) {}:Main . , string[] .

C# (value type) (reference type) System.Object . System.Object . System.Object System.ValueType .

CLR . . 0 . . . null .:

C# . . . , .C# .

byte, sbyte, short, ushort, int, uint, long, ulong :sbyte sb = sbyte.MinValue;string s = 15;byte b = byte.Parse(s);Console.WriteLine(sb); // -128Console.WriteLine(B); // 15short sh = short.MaxValue;console.WriteLine(sh); // 32767

float, doublefloat: 1.5*10-45 c 3.4*1038 7 double: 5*10-324 1.7*10308 15-16 float F .double D . : float: 0.0f, double: 0.0d NaN(Not a Number) .

decimal :decimal: 128 , 28 decimal M . : decimal: 0.0m decimal iRate = 3.9834M;iRate = decimal.Round(iRate,2);decimal p = decimal.Parse(100.05);

bool :bool: true, falsebool . bool bt = true; string bStr = bt.ToString(); // true bt = (bool) 1; //

char: 0..65535 16 .ushort . .bool bt;string pattern = 123acd;myChar = pattern[0];// 1bt = char.IsLetter(pattern, 3);// true (a)bt = char.IsNumber(pattern, 3); // false

enum enum .enum 0,1,2,3 . enum . internal . Public . .

enum

- struct . , , , , . , . . , .

struct

stringSystem.String string 16 . 2 . path = c:\\my documents\\notes.txt ; @ path = @c:\\my documents\\notes.txt; System.String .

System.String

Array [] = new [n] [{ }]System.Array .:int[] myIntArray;myIntArray = new int[5];int[] myIntArray = new int[5]{2,4,6,8,10};Int[] myIntArray = {2, 4, 6, 8, 10};

System.Array

static void Main() {int a;int b = 2, c = 3;a = 1;Console.WriteLine( a + b + c ); }

static void Main() {const float pi = 3.1415927f;const int r = 25;Console.WriteLine(pi * r * r);}

If static void Main(string[] args) {if(args.Length == 0) {Console.WriteLine(No arguments);}else {Console.WriteLine(One or more arguments);}}

switch static void Main(string[] args) {int n = args.Length;switch (n) {case 0:Console.WriteLine(No argumetns);break;case 1:Console.WriteLine(One argument);break;default :Console.WriteLine({0} arguments, n);break;}}

While static void Main(string[] args) {int i = 0;while(i < args.Length) {Console.WriteLine(args[i]);i++;}}

do static void Main() {string s;do {s = Console.ReadLine();if(s != null)Console.WriteLine(s);} while(s != null);}

for static void Main(string[] args) {for( int i = 0; i < args.Length; i++) {Console.WriteLine(args[i]);}}

foreach static void Main(string[] args) {foreach( string s in args) {Console.WriteLine(s);}}

break static void Main() {while(true) {string s = Console.ReadLine();if(s == null)break;Console.WriteLine(s);}}

continue static void Main(string[] args) {for( int i = 0; i < args.Length; i++) {if(args[i].StartsWith(/))continue;Console.WriteLine(args[i]);}}

goto static void Main(string[] args) {int i = 0;goto check;loop:Console.WriteLine(args[i++]);check:if(i < args.Length)goto loop;}

return static int Add(int a, int b) {return a+b;}

static void Main() {Console.WriteLine(Add(1,2));return;}