.


:




:

































 

 

 

 


RangeArray .




// .

int[] ; // int lowerBound; // int upperBound; //

. RangeArray. lowerBound, upperBound.

Length Error.

// Length, public int Length { get; private set; }

// Error, public bool Error { get; private set; }

, set private. , , , .

RangeArray.

// , public RangeArray(int low, int high) { high++;

if(high <= low) {

Console.WriteLine(" ");

high = 1; //

low = 0;

}

= new int[high - low];

Length = high - low;

lowerBound = low; upperBound = high;

}

RangeArray low, high. high , low high . : . , , . , . Length . , lowerBound upperBound.

RangeArray , .

// RangeArray. public int this[int index] {

// get. get {

if(ok(index)) {

Error = false;

return a[index - lowerBound];

} else {

Error = true; return 0;

}

// set. set {

if(ok(index)) {

a[index - lowerBound] = value;

Error = false;

}

else Error = true;

}

}

, FailSof tArray, . , .

Index - lowerBound

, index, , . lowerBound: , .

ok ().

// true, // , private bool ok(int index) {

if(index >= lowerBound & index <= upperBound) return true; return false;

}

FailSof tArray, , lowerBound upperBound.

RangeArray , . , , . , , , , . .

 

 

11

- , . , , . , , .

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

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

// , class TwoDShape {

Public double Width;

Public double Height;

public void ShowDimO {

Console.WriteLine(" " +

Width + " " + Height);

}

}

TwoDShape , .. , . , TwoDShape Triangle. Triangle.

// , using System;

// . class TwoDShape {

public double Width; public double Height; public void ShowDimO {

Console.WriteLine(" " +

Width + " " + Height);

}

}

// Triangle, TwoDShape. class Triangle: TwoDShape {

public string Style; //

// , public double Area() {

return Width * Height / 2;

}

// , public void ShowStyleO {

Console.WriteLine(" " + Style);

}

}

class Shapes {

static void Main() {

Triangle tl = new Triangle(); Triangle t2 = new Triangle();

tl.Width = 4.0;

tl.Height = 4.0;

tl.Style = "";

t2.Width = 8.0;

t2.Height = 12.0;

t2.Style = "";





:


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


:

:

- , , .
==> ...

1570 - | 1372 -


© 2015-2024 lektsii.org - -

: 0.018 .