Задать вопрос
VladOsadchyi
@VladOsadchyi
Студент

Почему индексатор ничего не выводит?

Почему Console.WriteLine("{0}", SumDU[1]); ничего не выводит в консоль?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace L2z4
{
    public class SignEx : System.Exception
    {
        public SignEx() { }
        public override string Message
        {
            get
            {
                return "Некоректний формат";
            }
        }
    }
        class Base
        {
            private string _Name;
            private string _TypeVlasn;
            private string _HeadSurname;
            private DateTime _BirthDate;
            private int _NumberWorker;
            public Base(string TheName, string TheTypeVlasn, string TheHeadSurname, DateTime TheBirthDate, int TheNumberWorker)
            {
                _Name = TheName;
                _TypeVlasn = TheTypeVlasn;
                _HeadSurname = TheHeadSurname;
                _BirthDate = TheBirthDate;
                _NumberWorker = TheNumberWorker;
            }
            public string Name
            {
                set { _Name = Name; }
                get { return _Name; }
            }
            public string TypeVlasn
            {
                set { _TypeVlasn = TypeVlasn; }
                get { return _TypeVlasn; }
            }
            public string HeadSurname
            {
                set { _HeadSurname = HeadSurname; }
                get { return _HeadSurname; }
            }
            public DateTime BirthDate
            {
                set { _BirthDate = BirthDate; }
                get { return _BirthDate; }
            }
            public int NumberWorker
            {
                set { _NumberWorker = NumberWorker; }
                get { return _NumberWorker; }
            }
            public int GetAge()
            {
                return (int)(DateTime.Now.Subtract(BirthDate).Days / 365.25);
            }
            public string FullName()
            {
                return (string)(Name + " " + TypeVlasn + " ");
            }
            public Base(string TheName, string TheTypeVlasn, string TheHeadSurname)
            {
                _Name = TheName;
                _TypeVlasn = TheTypeVlasn;
                _HeadSurname = TheHeadSurname;
            }
            public int GetAge(DateTime A)
            {
            return (int)(A.Subtract(BirthDate).Days / 365.25);
            }
        }

        class Company : Base
        {
            private string _SferaDiyalnosti;
            public Company(string TheName, string TheTypeVlasn, string TheHeadSurname, DateTime TheBirthDate, int TheNumberWorker, string TheSferaDiyalnosti)
                : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
            {
                _SferaDiyalnosti = TheSferaDiyalnosti;
            }
            public string SferaDiyalnosti
            {
                set { _SferaDiyalnosti = SferaDiyalnosti; }
                get { return _SferaDiyalnosti; }
            }
            public Company(string TheName, string TheTypeVlasn, string TheHeadSurname)
                : base(TheName, TheTypeVlasn, TheHeadSurname)
            { }

        }
        class Education : Base
        {
            new private string _Name;
            private string _TypeVlasn;
            private string _HeadSurname;
            private long _PhoneNumber;
            public Education(string TheName, string TheTypeVlasn, string TheHeadSurname, DateTime TheBirthDate, int TheNumberWorker, long ThePhoneNumber)
                : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
            {
                _PhoneNumber = ThePhoneNumber;
            }
            public Education(string TheName, string TheTypeVlasn, string TheHeadSurname)
                : base(TheName, TheTypeVlasn, TheHeadSurname){ }
        public string this[int index]
        {
            set
            {
                switch (index)
                {
                    case 0:
                        _Name = Name;
                        break;
                    case 1:
                        _TypeVlasn = TypeVlasn;
                        break;
                    case 2:
                        _HeadSurname = HeadSurname;
                        break;
                }
            }
            get
            {
                switch (index)
                {
                    case 0: return _Name;
                    case 1: return _TypeVlasn;
                    case 2: return _HeadSurname;
                    default:
                        return "";
                }
            }
        }
        public long PhoneNumber
            {
                set { _PhoneNumber = PhoneNumber; }
                get { return _PhoneNumber; }
            }
            public string Name
            {
                set { _Name = Name; }
                get { return base.Name; }
            }

       
        }
        class Bank : Base
        {
            private float _Profit;
            public Bank(string TheName, string TheTypeVlasn, string TheHeadSurname, DateTime TheBirthDate, int TheNumberWorker, float TheProfit)
                : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
            {
                _Profit = TheProfit;
            }
            public float Profit
            {
                set { _Profit = Profit; }
                get { return _Profit; }
            }
            public Bank(string TheName, string TheTypeVlasn, string TheHeadSurname)
                : base(TheName, TheTypeVlasn, TheHeadSurname)
            { }
        }
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    Education School = new Education("Школа №1", "Державна", "Осадча", new DateTime(1948, 04, 24), 56, 380991133444);
                    Education SumDU = new Education("Sumy State Un.", "State", "petrov");
                    string Name = School.Name;
                    string Surname = School.HeadSurname;
                    char[] N = Name.ToCharArray();
                    char[] S = Surname.ToCharArray();
                    string N1 = N[0].ToString();
                    string S1 = S[0].ToString();
                if (Regex.IsMatch(N1, @"[А-Я]") && Regex.IsMatch(S1, @"[А-Я]") && DateTime.Now.Subtract(School.BirthDate).Days / 365.25 < 120 && DateTime.Now.Subtract(School.BirthDate).Days / 365.25 > 5)
                {
                    Console.WriteLine("{0}", School.FullName());
                    Console.WriteLine("{0}", School.Name);
                    Console.WriteLine("{0}", SumDU[1]);
                    Console.WriteLine("{0}", School.GetAge(new DateTime(2012, 11, 21)));
                }
                    else
                    {
                        throw new SignEx();
                    }
                }
                catch (SignEx m)
                {
                    Console.WriteLine(m.Message);
                }
                Console.ReadKey();
            }
        }
    }
  • Вопрос задан
  • 324 просмотра
Подписаться 1 Простой Комментировать
Решения вопроса 1
0xD34F
@0xD34F
Вот в этом фрагменте символы подчёркивания - долой:


switch (index)
{
    case 0: return _Name;
    case 1: return _TypeVlasn;
    case 2: return _HeadSurname;
    default:
        return "";
}


Ну и сеттеры у вас все кривые тоже.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы