Monday, July 29, 2013

C# Public Override Method

May be you can use a Boolean member to decide whether or not to show EEID. For example, in below code, one can set CanShowEEID to display or not display EEID.



public class Person
{
int eeid;
public int EEID
{
get { return eeid; }
set { eeid = value; }
}

string firstname;
public string Firstname
{
get { return firstname; }
set { firstname = value; }
}

string lastname;
public string Lastname
{
get { return lastname; }
set { lastname = value; }
}

public bool CanShowEEID { get; set; }

public override string ToString()
{
string result = Firstname + " " + Lastname;
result = CanShowEED ? EEID + " " + result : result;
return result;
}
}



I hope this helps.


Please mark this post as answer if it solved your problem. Happy Programming!


No comments:

Post a Comment