:
class _
{
//
//
}
.
namespace Klass1
{
Class kl1
{
int n; //
int []a;
public kl1(int k1) //
{
n=k1;
a=new int[k1];
for(int i=0;i<n;i++)
{
Console.Write("Input "+i+" ");
a[i]=Convert.ToInt32(Console.ReadLine());
}
}
~kl1() //
{
Console.WriteLine("I am the destructor");
}
//
public void param(out int s)
{
s=0;
for(int i=0;i<n;i++)
s+=a[i];
}
public void val(ref int p)
{
// ,
int sum=0;
if(p>=n)p=-5;
else{
for(int i=p;i<n;i++)
sum+=a[i];
p= sum;}
}
public void out_a()
{
for(int i=0;i<n;i++)
Console.WriteLine(" Element a("+i+")="+a[i]);
}
public int get_n()
{
return n;
}
}
class Class1
{
static void Main(string[] args)
{
kl1 kk1; //
int l,m;
Console.Write("Input the count of Elem ");
m=Convert.ToInt32(Console.ReadLine());
kk1=new kl1(m); //
l=kk1.get_n(); //
Console.WriteLine(": "+l);
kk1.out_a();
kk1.param(out l);
Console.WriteLine(" = "+l);
l=m-3; // l
kk1.val(ref l);
Console.WriteLine(" = "+l);
Console.ReadLine();
} } }
. :
private (): , private .
protected (): protected - .
public (): public .
++ C# ; private.
l1 n a, private.
, , . , public, (). , . , . . . , , . C# , . , . !
|
|
, ~_() . C# . , . , C# , , . .
. . .
C# : ( ) , , ( / ) . . , .
Main(). kl1 kk1; C# , . kk1=new kl1(m); . . out, ref.
: . . , , . ; (=), (+= ..).
:
public static __ operator _ ()
{
//
}
. , : , , , (, , ). C#, <, >. Ÿ . .
namespace ConApp5
{
class array
{
int[] a;
int n;
public array(int k)
{
n = k;
a=new int [k];
}
public array(array z)
{
// ,
//
int m = z.a.Length;
a = new int[m];
|
|
}
public void inpt()
{
//
for (int i = 0; i < a.Length; i++)
{
Console.Write("a[" + i + "]=");
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void outp()
{
//
for (int i = 0; i < a.Length; i++)
Console.WriteLine("a[" + i + "]=" + a[i]);
}
public static array operator +(array op1, array op2)
{
//
//
array temp = new array(op1.n);
for (int i = 0; i < temp.n; i++)
{
temp.a[i] = op1.a[i] + op2.a[i];
}
return temp;
}
public static array operator +(array op1, int op2)
{
// ,
//
array temp = new array(op1.n);
for (int i = 0; i < temp.n; i++)
{
temp.a[i] = op1.a[i] + op2;
}
return temp;
}
public static bool operator <(array op1, array op2)
{
// ( >)
bool b1 = true;
for (int i = 0; i < op1.n; i++)
{
if (op1.a[i] > op2.a[i]) b1 = false;
}
return b1;
}
public static bool operator >(array op1, array op2)
{
// ( <)
bool b1 = true;
for (int i = 0; i < op1.n; i++)
{
if (op1.a[i] < op2.a[i]) b1 = false;
}
return b1;
}
public static array operator -(array op1, array op2)
{
//
//
array temp = new array(op1.n);
for (int i = 0; i < temp.n; i++)
{
temp.a[i] = op1.a[i] - op2.a[i];
}
return temp;
}
public static array operator ++(array op)
{
//
for (int i = 0; i < op.n; i++)
op.a[i]++;
return op;
}
}
class Program
{
static void Main(string[] args)
{
array a1, a2, a3;
bool q1, q2;
a1 = new array(4);
a1.inpt();
a2 = new array(4);
a2.inpt();
a3 = new array(4);
a3 = a1 + a2; //
a3.outp();
a1++; //
a1.outp();
a3 = a1 + 10; //
a3.outp();
q1 = a1 < a2; //
q2 = a1 > a2;
Console.WriteLine("BOOL " + q1 + " " + q2);
Console.ReadLine();
} } }
, , z ! .
, . :
__ this [int ]
{
get
{
//
}
set
{
//
}
}
( private), public private.
. Array a
namespace Index_1
{
class Array
{
int []a;
public int len;
public bool err;
public Array(int n)
{ //
a=new int[n];
len = n;
}
//
public int this[int index]
{
get //
{
if(ok(index))
{
err=false;
return a[index];
}
else
{
err=true;
return 0;
}
}
Set //
{
if(ok(index))
{
a[index]=value;
err=false;
}
else
{
err=true;
}
}
}
bool ok(int index)
{
// ,
if((index>=0)&&(index<len))return true;
else return false;
}
}
class Class1
{
static void Main(string[] args)
{
Array c1=new Array(5);
for(int i=0;i<c1.len;i++)
|
|
c1[i]=2*i; // set
for(int i=0;i<c1.len;i++)
Console.WriteLine("Array["+i+"]="+c1[i]);
// get
Console.ReadLine();
}
}
}
c1[i] c1.a[i]. , public; c1.a[i] .
. (, ).
. , . , . .
namespace Katse
{
class Class1
{
struct mas1
//class mas1
// , ()
{
public double []d1;
public mas1(int n)
{
d1=new double[n];
}
public double this[int index]
{ //
get{return d1[index];}
set{d1[index]=value;}
}
}
static mas1 sum11(double [,]x)
{mas1 my=new mas1(x.GetUpperBound(0)+1);
// mas1
for(int i=0;i<=x.GetUpperBound(0);i++)
for(int j=0;j<=x.GetUpperBound(1);j++)
my[i]+=x[i,j];
return my;
}
static void Main(string[] args)
{
double [,]arr;
arr=new double[5,3];
mas1 m1=new mas1(5);//
for(int i=0;i<5;i++)
{for(int j=0;j<3;j++)
{arr[i,j]=(2+i)*(j+4);
Console.Write("Rida ["+i+","+j+"]="+arr[i,j]+" ");}
Console.WriteLine();}
m1=sum11(arr);
for(int i=0;i<5;i++)
Console.WriteLine("Summa "+i+" on "+m1[i]);
// m1[i]
Console.ReadLine();
} } }
. , . (, - - , ; ...). , , , .
:
__ _
{
get {
//
}
set {
//
} }
.
namespace ConApp7
{
class Prop1
{
double[] mas;
double lim;
public Prop1()
{
int n;
Console.Write("? ");
n = Convert.ToInt32(Console.ReadLine());
mas = new double[n];
for (int i = 0; i < n; i++)
{
Console.Write("Mas[" + i + "]=");
mas[i] = Convert.ToDouble(Console.ReadLine());
}
}
double sum()
{ //
double s=0;
for(int i=0;i<mas.Length;i++)
if(mas[i]>lim)s+=mas[i];
return s;
}
public double sum_prop
{ // ,
get { if (sum() > 0) return sum(); else return -25; }
}
public double lim_prop
{ // ,
get { return lim; }
set { if (value > 0)lim = value; else lim = 0; }
}
}
class Program
{
static void Main(string[] args)
{
Prop1 pr2=new Prop1();
//
|
|
pr2.lim_prop = 23.5;
//
Console.WriteLine(" " + pr2.sum_prop);
Console.WriteLine(" " + pr2.lim_prop);
Console.ReadLine();
} } }
: ? ? . , , ( ). , , , . , - . , , , .
. , . ref- out-. get.
, mas.Length mas.GetLength(0). , , .