venus najad

venus najad

  • 1.3k
  • 414
  • 27.9k

property and class variable inside a loop

Feb 21 2019 4:35 AM
hello... i have made a class student with a public string variable s1 and a RW property index...
in main method i read into index from the screen and in a loop is in main i check the value of s1, which is sets by index property... in my class student, i have a loop but the context of s1 is empty???!!!  i aprreciate any help... regards
 
class Student{
public string s1;
public string index
{
get{return this.s1;}
set{ this.s1 = value; }
}
if(s1=="y"){...}
else{...}
 
static void Main(string[] args)
{
Student st = new Student();
Console.WriteLine("please choose y or n");
st.index = Console.ReadLine();
if (st.s1 == "y"||st.s1=="n"){....}
else {.....}
 

Answers (6)