Mark Tabor

Mark Tabor

  • 589
  • 2k
  • 456.9k

IF else condition in c#

Apr 3 2023 5:15 PM

I have a table of students in which I have few columns like ID,Name,Class,Subject,Marks Now in my table I have these records

ID Name Class Subject Marks
1 ASAD 5th ENG 190
2 USMAN 6th MATH 200
3 ALI 4th ENG 100
4 ABC 4th MTH 78
5 BYH 3rd ENG 98
6 BHJ 2nd ENG 89
7 new 5th MATH 76

I like to apply IF conditions and show only those records who are having class 5th and 4th and if class is not equal to 5th or 4th then I wanted to show a message.

the issue is explained below

if(st.class!="5th")

{

Print My Message

}

if(st.class!="4th")

{

print my message

}

This issue is that even if my student is having class "4th" then it still shows the message because it execute the first if condition and it shows the message,it should not show as my second if has class 4th which .

THE ISSUE IS like IF A STUDENT IS HAVING CLASS 4th that is allowed class but the first IF already run and it shows the message how to combine these two if in one  if I make the statement like this 

if(st.class!="4th" || st.class!="5th") (THEN FROM IT AS IT IS OR OPERATOR IF ONE CONDITION IS TRUE IT WILL BE TRUE , the student must have either 4th or 5th class not both

{

 

}


Answers (3)