Why indexer does not output anything?

Why Console.WriteLine("{0}", SumDU[1]); does not output anything to the console?
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 "Nekorekti format";
}
}
}
 class Base
{
 private string _Name;
 private string _TypeVlasn;
 private string _HeadSurname;
 private DateTime _BirthDate;
 private int _NumberWorker;
 public Base(string TheName, string TheTypeVlasn, TheHeadSurname string, 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, TheHeadSurname string, DateTime TheBirthDate, TheNumberWorker int, 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, TheHeadSurname string, 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, TheHeadSurname string, DateTime TheBirthDate, TheNumberWorker int, 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
{
 School Education = new Education("School №1", "sovereign", "Osadcha", new DateTime(1948, 04, 24), 56, 380991133444);
 SumDU Education = 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, @"[A-Z]") && Regex.IsMatch(S1, @"[A-Z]") && 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();
}
}
 }
June 14th 19 at 19:12
2 answers
June 14th 19 at 19:14
Solution
Here in this passage underscores - down:
switch (index)
{
 case 0: return _Name;
 case 1: return _TypeVlasn;
 case 2: return _HeadSurname;
default:
 return "";
}

Well, the setters you have all the curves too.
how you think I did the right thing? - renee_Klock commented on June 14th 19 at 20:17
And possibly curves, but the job I have is....
So it turns out bad programmers, because in the Institute it should do as you say.... - renee_Klock commented on June 14th 19 at 19:17
works))
if not difficult can you tell me why the underscore is not needed(because in the example it is) and why setters curves?? - renee_Klock commented on June 14th 19 at 19:20
don't know what you got there for example, but properties whose values you are returning, what is declared twice in the base class and the child. When you create an object of child class values are set only for those properties which belong to the base class. And when obtaining the value of the properties owned by the child class - uninitialized. This is why "the indexer does not output anything".

Now the underscore. In the base class you have declared getters/setters with the same names as the properties, only without the underscore - that is, removing the underscore makes an appeal to the property of the child class to call the getter of the base class that returns a property value from the base class.

So redeclaring the properties in the child class it would be better to cut. If you want to contact them directly in the methods of the child class - change base class access modifiers to protected.

What else? Oh yeah, why setters curves. So do not work the same. You tried to use? - favian_Torp12 commented on June 14th 19 at 19:23
I don't understand why they are declared in a child class wrote this code from the example, so they show up twice. and if you cut them in the child class then nothing works - renee_Klock commented on June 14th 19 at 19:26
here is an example, if you're interested, you can job to throw - renee_Klock commented on June 14th 19 at 19:29
, "nothing works" is talking about nothing. And of one removal is not enough - either work with inherited properties in a child class using getters/setters, or change the access modifiers in the base class.

here is an example

Well, at least there are properties of a child class, which your code doesn't have. - favian_Torp12 commented on June 14th 19 at 19:32
bad programmers not because of "bad" jobs, and due to the fact that "perform" these jobs not realizing that doing "their" code. - Anabel.Donnelly commented on June 14th 19 at 19:35
well , so I'm trying to understand my code. if I just wanted to pass the lab, it could take senior courses ready code and no steam - renee_Klock commented on June 14th 19 at 19:38
perhaps I'm too dumb to understand all this.......((

But why initialize the properties in the child class, they are initialized in the parent??

Or I don't understand what properties you are talking.......(( - renee_Klock commented on June 14th 19 at 19:41
the properties _Name, _TypeVlasn, _HeadSurname. Declared in the Base class, and inherited from his Education. In the base class constructor you assign values. And in the constructors of the child - not. - favian_Torp12 commented on June 14th 19 at 19:44
I think I understand what you mean. I honestly did not know that in the child class in the constructor to do it. as I understand it, with the constructor overload not need to do this?? - renee_Klock commented on June 14th 19 at 19:47
here it is not clear why in example the example in the child class Student declared fields:
new private string _Surname;
 private string _Group;
 private string _Name;
 private string _Patronymic;

if they are declared in the Human, and I understand they should be inherited from it, or they are not inherited due to the fact that the mod. private access?? - renee_Klock commented on June 14th 19 at 19:50
I don't understand why it was made. - favian_Torp12 commented on June 14th 19 at 19:53
maybe they are not inherited due to the fact that the mod. private access?? - renee_Klock commented on June 14th 19 at 19:56
inherited. Just in case private for them not to be access out of the base class.

You better have the author of your example ask, the hell he did that. - favian_Torp12 commented on June 14th 19 at 19:59
I suspect that this example ten years, and the one who did it no longer works in my high school............ - renee_Klock commented on June 14th 19 at 20:02
that code that I write, I have done these are the indexers, is that correct?
class Education : Base
{
 new private string _Name;
 private string _TypeVlasn;
 private string _HeadSurname;
 private DateTime _BirthDate;
 private long _PhoneNumber;
 public Education(string TheName, string TheTypeVlasn, TheHeadSurname string, DateTime TheBirthDate, int TheNumberWorker, long ThePhoneNumber)
 : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
{
 _Name = TheName;
 _TypeVlasn = TheTypeVlasn;
 _HeadSurname = TheHeadSurname;
 _BirthDate = TheBirthDate;
 _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 = value;
break;
 case 1:
 TypeVlasn = value;
break;
 case 2:
 HeadSurname = value;
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; }
}


 }
- renee_Klock commented on June 14th 19 at 20:05
whether? I believe that you know better. Well, if it works as it should - so right. - favian_Torp12 commented on June 14th 19 at 20:08
the fact is that I don't know if this is correct)) but it works)) - renee_Klock commented on June 14th 19 at 20:11
if you do not declare those fields in the child class, the constructor of child class when I give the value of such error is 'Base._Name"(_TypeVlasn, _HeadSurname, _BirthDate) is inaccessible due to its protection level

class Education : Base
{

 private long _PhoneNumber;
 public Education(string TheName, string TheTypeVlasn, TheHeadSurname string, DateTime TheBirthDate, int TheNumberWorker, long ThePhoneNumber)
 : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
{
 _Name = TheName;
 _TypeVlasn = TheTypeVlasn;
 _HeadSurname = TheHeadSurname;
 _BirthDate = TheBirthDate;
 _PhoneNumber = ThePhoneNumber;
 }


so I came up with in the constructor of the child class can access the base class
class Education : Base
{

 private long _PhoneNumber;
 public Education(string TheName, string TheTypeVlasn, TheHeadSurname string, DateTime TheBirthDate, int TheNumberWorker, long ThePhoneNumber)
 : base(TheName, TheTypeVlasn, TheHeadSurname, TheBirthDate, TheNumberWorker)
{
 Name = TheName;
 TypeVlasn = TheTypeVlasn;
 HeadSurname = TheHeadSurname;
 BirthDate = TheBirthDate;
 PhoneNumber = ThePhoneNumber;
 }
- renee_Klock commented on June 14th 19 at 20:14
June 14th 19 at 19:16
Apparently all too lazy to read this code((

Find more questions by tags C#