Enum.HasFlag method in C# 4.0
Join the DZone community and get the full member experience.Join For Free
public enum PaymentType
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;
Response.Write("Process Debit Card");
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. That’s it It’s so simple and cool. Stay tuned for more.. Happy Programming..
Published at DZone with permission of Jalpesh Vadgama, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.