Articles → .NET → Flags attribute in enums C#

Flags attribute in enums C#
















Software requirement





Technical knowledge















Syntax


[Flags]
public enum Enum_Name
{
}



Example














public bool IsEligibleToContestElection(bool above18, bool resident, bool graduate, bool nocriminalbackground)
{
  if (above18 == true && resident == true && graduate == true && nocriminalbackground == true)
     return true;
       else
     return false;
 }




IsEligibleToContestElection(true, true, true, true)






[Flags]
public enum EligibilityCriteria
{
            Above18,
            IsResident,            
			AGraduate,
            NoCriminalBackground
}

public bool IsEligibleToContestElection(EligibilityCriteria criteria)
{
   if (criteria == (EligibilityCriteria.Above18 & EligibilityCriteria.IsResident & EligibilityCriteria.AGraduate & EligibilityCriteria.NoCriminalBackground))
     return true;
   else
     return false;
}




IsEligibleToContestElection(EligibilityCriteria.Above18 & EligibilityCriteria.IsResident & EligibilityCriteria.AGraduate & EligibilityCriteria.NoCriminalBackground)





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, October 29, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250