public enum PaymentType { DebitCard=1, CreditCard=2 }
Now We are going to assigned one of the value to this enum instance and then with the help of HasFlag method we are going to check whether particular value is assigned to enum or not like following.
protected void Page_Load(object sender, EventArgs e) { PaymentType paymentType = PaymentType.CreditCard; if (paymentType.HasFlag(PaymentType.DebitCard)) { Response.Write("Process Debit Card"); } if (paymentType.HasFlag(PaymentType.CreditCard)) { Response.Write("Process Credit Card"); } }
Now Let’s check out in browser as following.
As expected it will print process Credit Card as we have assigned that value to enum.
No comments:
Post a Comment