.


:




:

































 

 

 

 





 

, . .

namespace Nasl22

{

class mas1

{ // mas1

protected int[] a;

public mas1()

{ //

int n;

Console.Write("Elements ");

n = Convert.ToInt32(Console.ReadLine());

a = new int[n];

}

public void inpt()

{ //

for (int i = 0; i < a.Length; i++)

{

Console.Write("a[" + i + "]=");

a[i] = Convert.ToInt32(Console.ReadLine());

}

}

int sum()

{ //

int s=0;

for(int i=0;i<a.Length;i++)

s+=a[i];

return s;

}

public int summa

{ //

get { return sum(); }

}

public int this[int k]

{ //

get { return a[k];}

set { a[k] = value; }

}

}

class cl_a

{

public mas1 arr1; // mas1

int sm;

public cl_a()

{ // cl_a, mas1

arr1 = new mas1();

arr1.inpt();

}

public int st1()

{ // mas1

sm=arr1.summa;

return sm;

}

}

class Program

{

static void Main(string[] args)

{

cl_a my = new cl_a();

int n, m,r;

n = my.arr1.summa; //

r = my.st1(); // ,

// mas1

m = my.arr1[2]; //

Console.WriteLine("=" + n + " ="+

r+" [2] =" + m);

Console.ReadLine();

} } }

 

: , (, ). : !

namespace FunKlass

{

class dan

{ //

public string s1;

public int k;

}

class Program

{

static dan[] fun2()

{ // dan ,

// .

int n,m;

dan []w;

Console.Write("? ");

n = Convert.ToInt32(Console.ReadLine());

w = new dan[n]; //

for (int i = 0; i < n; i++)

{

w[i] = new dan(); //

Console.Write(" " + i + " ");

w[i].s1 = Console.ReadLine();

Console.Write(" " + i + " ");

w[i].k=Convert.ToInt32(Console.ReadLine());

}

return w;

}

static dan fun1(dan[] x)

{

string t1;

int max=0;

dan d1=new dan();

for (int i = 0; i < x.Length; i++)

{

if (max < x[i].k)

{

max = x[i].k;

d1 = x[i];

}

}

return d1;

}

 

 

static void Main(string[] args)

{

dan []b;

dan otv;

b = fun2(); //

otv = fun1(b); //

Console.WriteLine("Number= " + otv.k + " Name= " + otv.s1);

Console.ReadLine();

} } }

 

dan fun2.

class dan

{

public string s1;

public int k;

public dan()

{

Console.Write("Element String ");

s1 = Console.ReadLine();

Console.Write("Element number ");

k = Convert.ToInt32(Console.ReadLine());

}

}

static dan[] fun2()

{

int n,m;

dan []w;

Console.Write("Elements? ");

n = Convert.ToInt32(Console.ReadLine());

w = new dan[n];

for (int i = 0; i < n; i++)

{ //

w[i] = new dan();

}

return w;

}

 

 

: . . . C# . , , . . , , , . , ; . new, . , . , , . : ( ).

 

namespace StructFun

{

struct dan1

{

public string s1; // public

public int k;

}

class Program

{

static dan1[] inpt()

{ //

dan1[] temp;

int n;

Console.Write("Elements? ");

n = Convert.ToInt32(Console.ReadLine());

temp = new dan1[n];

for (int i = 0; i < n; i++)

{

Console.Write("Elem " + i + " Num ");

temp[i].k = Convert.ToInt32(Console.ReadLine());

Console.Write("Elem " + i + " Name ");

temp[i].s1 = Console.ReadLine();

}

return temp;

}

static double proc1(dan1 []x)

{ //

int s = 0;

for (int i = 0; i < x.Length; i++)

s += x[i].k;

return (double)s / x.Length;

}

static void Main(string[] args)

{

dan1[] id; //

double aver;

id = inpt(); //

aver = proc1(id); //

Console.WriteLine("Average=" + aver);

Console.ReadLine();

} } }

 

 

C# : . , , , . . : ; ; .

, , . private , , , . ( ) protected.

class arr

{

protected int[] k; // protected

// -

public arr()

{ // 1

int n;

Console.Write("? ");

n = Convert.ToInt32(Console.ReadLine());

k = new int[n];

for (int i = 0; i < n; i++)

{

Console.Write("K[" + i + "]=");

k[i] = Convert.ToInt32(Console.ReadLine());

}

}

public arr(int p)

{ // 2

k = new int[p];

for (int i = 0; i < p; i++)

{

Console.Write("K[" + i + "]=");

k[i] = Convert.ToInt32(Console.ReadLine());

}

}

public void output()

{

Console.WriteLine();

Console.WriteLine("Elements of Array");

for (int i = 0; i < k.Length; i++)

Console.WriteLine("K[" + i + "]=" + k[i]);

} }

 

. . - ( private). , .

 

class proc1: arr // arr

{

int q;

public proc1()

{ //

Console.Write(" ");

q = Convert.ToInt32(Console.ReadLine());

}

public int sum()

{

int s = 0;

for (int i = 0; i < k.Length; i++)

if (k[i] > q) s += k[i];

return s;

} }

class Program

{

static void Main(string[] args)

{

proc1 My = new proc1(); //1

int s1;

My.output(); //

s1=My.sum(); // ,

//

Console.WriteLine("Summa= " + s1);

Console.ReadLine();

} }

 

, , ( // 1) : . , . , .

, : . : () , 2. .

public proc1(int k1, int k2): base(k1)

{

q = k2;

}

base(k1), 1. :

 

 

static void Main(string[] args)

{

int s1;

proc1 Myaa = new proc1(6, 20); //

//

Myaa.output();

s1=Myaa.sum();

Console.WriteLine("Summa= " + s1);

Console.ReadLine();

}

: . , .

 

 

C# , . , , : . : -. .

namespace Virtual1

{

class X

{

public int a;

public X(int i) {a=i;}

}

class Y:X

{

public int b;

public Y(int i, int j): base(i) {b=j;}

}

class Class1

{

static void Main(string[] args)

{

X x1= new X(10);

X x2;

Y y1=new Y(15,100);

int k;

x2=x1; //,

Console.WriteLine("First "+x1.a+" Second "+x2.a);

x2=y1; //, Y X

Console.WriteLine("First "+x1.a+" Second "+x2.a);

 

// k=x2.b; - X b Console.ReadLine(); } } }

 

, , . . !

 

 

C# . , . , . , , , . . . , , . .

namespace Construct_Coop

{

class Shape

{

protected double a, h;

public Shape(double x, double y)

{ //

a = x;

h = y;

}

public Shape(Shape ob)

{ //

a = ob.a;

h = ob.h;

}

public void NewDan(double x,double y)

{

a = x;

h = y;

}

}

class Tri: Shape

{

protected double area;

public Tri(double x, double y): base(x, y)

{ // }

public Tri(Tri ob):base(ob) // 1

{ // }

public void Show_area()

{

area = a * h / 2;

Console.WriteLine("S_Treug="+ area);

}

}

class Square: Shape

{

protected double area;

public Square(double x, double y): base(x, y) { }

public Square(Square ob): base(ob) { } // 1

public void Show_area()

{

area = a * h;

Console.WriteLine("S_Squar="+ area);

}

}

class Program

{

static void Main(string[] args)

{

Tri my=new Tri(5,12); //

my.Show_area();

Tri w = my; //

w.NewDan(50, 120); // w

my.Show_area(); //

w.Show_area();

Tri u = new Tri(w); //

u.NewDan(500, 1200); // u

w.Show_area();//

u.Show_area();

Console.ReadLine();

} } }

 

// 1: (Shape) - (Tri, Square).

 

 

, virtual, . - , override. C# ( , 3.9.). . , . . , , , , . , . , . .

.

namespace Virtual1

{

class Shape

{

protected int a,h;

public Shape (int x,int y)

{

a=x;

h=y;

}

public virtual void Show_area()

{ //

Console.WriteLine(" ");

}

}

class Tri:Shape

{

int s;

public Tri(int x, int y):base(x, y)

{}

public override void Show_area()

{ //

s=a*h/2;

Console.WriteLine(" = "+s);

}

}

class Square:Shape

{

int s;

public Square(int x, int y):base(x, y)

{}

public override void Show_area()

{ //

s=a*h;

Console.WriteLine(" = "+s);

}

}

 

class Class1

{

static void Main(string[] args)

{

Shape q=new Shape(10,30);

q.Show_area();

//

Tri z1=new Tri(5,12);

z1.Show_area();

//

Shape w;

w=z1; // w Tri

w.Show_area(); // Tri.Show_area()

//

Square w1=new Square(5,12);

w1.Show_area();

//

w=w1; // w Square

w.Show_area(); //Square.Show_area()

Console.ReadLine();

} } }

 

, w Shape, Shape. , w.Show_area(); Show_area().

 

 





:


: 2016-11-24; !; : 448 |


:

:

, , .
==> ...

1831 - | 1483 -


© 2015-2024 lektsii.org - -

: 0.619 .