.


:




:

































 

 

 

 


. . .




C# , ; , . , , , C# . params.

, . . .

// .

Using System;

class MyClass { public int x;

public MyClass() {

Console.WriteLine(" MyClass()."); x = 0;

}

public MyClass(int i) {

Console.WriteLine(" MyClass(int)."); x = i;

}

public MyClass(double d) {

Console.WriteLine(" MyClass(double)."); x = (int) d;

}

public MyClass(int i, int j) {

Console.WriteLine(" MyClass(int, int)."); x = i * j;

}

}

class OverloadConsDemo { static void MainO- {

MyClass tl = new MyClass ();

MyClass t2 = new MyClass(88);

MyClass t3 = new MyClass(17.23);

MyClass t4 = new MyClass(2, 4);

Console.WriteLine("tl.x: " + tl.x);

Console.WriteLine("t2.: " + t2.x);

Console.WriteLine("t3.x: " + t3.x);

Console.WriteLine("t4.x: " + t4.x);

}

}

.

MyClass().

MyClass (int).

MyClass(double).

MyClass (int, int). tl.x: t2.x: 88 t3.x: 17 t4.x: 8

MyClass () , -. , , new. .

. Stack, .

// .

Using System;

class Stack {

// , char[] stck; // , int tos; //

// Stack , public Stack(int size) {

stck = new char[size]; // tos = 0;

}

// Stack , public Stack(Stack ob) {

// , stck = new char[ob.stck.Length];

// , for (int i=0; i < ob.tos; i++) stck[i] = ob.stck[i];

// tos , tos = ob.tos;

// , public void Push(char ch) { if(tos==stck.Length) {

Console.WriteLine(" - ."); return; -

}

stck[tos] = ch; tos++;

}

// , public char Pop () {

if(tos==0) {

Console.WriteLine (" - ."); return (char) 0;

}

Tos;

return stck[tos];

}

// true, , public bool IsFullO { return tos==stck.Length;

}

// true, , public bool IsEmptyO { return tos==0;

}

// , public int Capacity() {

Return stck.Length;

}

// , , public int GetNum() { return tos;

}

}

// Stack.

class StackDemo {

static void Main() {

Stack stkl = new Stack(10); char ch; int i;

// stkl.

Console.WriteLine(" -J stkl."); for(i=0;!stkl.IsFull(); i++)

stkl.Push((char) ('A' + i));

// stckl.

Stack stk2 = new Stack(stkl);

// stkl.

Console.Write(" stkl: "); while (!stkl.IsEmpty()) {

ch = stkl.Pop ();

Console.Write(ch);

}

Console.WriteLine ();

Console.Write(" stk2: "); while (!stk2.IsEmpty()) {

ch = stk2.Pop ();

Console.Write(ch);

}

Console.WriteLine ("\n");

}

}





:


: 2016-12-03; !; : 345 |


:

:

- , , .
==> ...

1388 - | 1210 -


© 2015-2024 lektsii.org - -

: 0.014 .