Equals() মেথড দুটি এনাম মান সমান কিনা চেক করে (আন্ডারলাইং ইন্টিজার ভ্যালু তুলনা করে)।
উদাহরণ
using System;
class Program
{
enum Products { HardDrive, PenDrive, Keyboard };
enum ProductsNew { Mouse, HeadPhone, Speakers };
static void Main()
{
Products prod1 = Products.HardDrive;
Products prod2 = Products.HardDrive;
ProductsNew newProd1 = ProductsNew.HeadPhone;
ProductsNew newProd2 = ProductsNew.Speakers;
Console.WriteLine("Both are same products = {0}", prod1.Equals(prod2) ? "Yes" : "No");
Console.WriteLine("Both are same products = {0}", newProd1.Equals(newProd2) ? "Yes" : "No");
}
}
আউটপুট
Both are same products = Yes Both are same products = No
একই এনাম টাইপের মান তুলনা করলে সঠিক ফলাফল দেয়। ভিন্ন এনাম টাইপ তুলনা করলে false দেয় (এবং কম্পাইলার ওয়ার্নিং দেয়)।