enums মধ্যে সমতা খুঁজে পেতে, Equals() পদ্ধতি ব্যবহার করুন।
ধরা যাক আমাদের নিম্নলিখিত Enum আছে।
enum Products { HardDrive, PenDrive, Keyboard}; দুটি পণ্য বস্তু তৈরি করুন এবং একই মান নির্ধারণ করুন।
Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive;
এখন 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