Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace lab_4
- {
- class Safearray
- {
- readonly int LIMIT = 12;
- protected int[] Arr;
- public int getLimit()
- {
- return LIMIT;
- }
- public Safearray()
- {
- Arr = new int[LIMIT];
- }
- public int this[int n]
- {
- get
- {
- if ((n < 0) || (n > LIMIT))
- {
- Console.Write("\nОшибочный индекс!");
- return 0;
- }
- else
- {
- return Arr[n];
- }
- }
- set
- {
- if ((n < 0) || (n > LIMIT))
- {
- Console.Write("\nОшибочный индекс!");
- }
- else
- {
- Arr[n] = value;
- }
- }}
- class Safehilo : Safearray {
- private int low;
- private int high;
- public Safehilo(int low, int high):base() {
- this.low=low;
- this.high=high;
- Arr=new int[high-low];
- }
- public int this[int n]
- {
- get
- {
- if ((n < low) || (n >= high))
- {
- Console.Write("\nОшибочный индекс!");
- return 0;
- }
- else
- {
- return Arr[n-low];
- }
- }
- set
- {
- if ((n < low) || (n >= high))
- {
- Console.Write("\nОшибочный индекс!");
- }
- else
- {
- Arr[n-low] = value;
- }
- }
- }}
- class Program
- {
- static void Main(string[] args)
- {
- //Console.WriteLine("Hello World!");
- string low, high;
- Console.WriteLine("Enter low: ");
- low=Console.ReadLine();
- Console.WriteLine("Enter high: ");
- high=Console.ReadLine();
- int l=Convert.ToInt32(low);
- int h=Convert.ToInt32(high);
- Safehilo mas=new Safehilo(l, h);
- for (int i=0; i<(h-l); i++){
- mas[l+i]=i;
- Console.WriteLine("mas[{0}]: {1}", l+i, mas[l+i]);
- }
- Console.WriteLine(mas[l+3]);
- }
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement