Phương thức SByte.Equals () trong C # được sử dụng để trả về một giá trị cho biết thể hiện này bằng một đối tượng cụ thể hay SByte.
Cú pháp
Cú pháp như sau -
public bool Equals (sbyte ob); public override bool Equals (object ob);
Ở trên, tham số ob cho một giá trị SByte để so sánh với trường hợp này, trong khi tham số ob cho 2 nd cú pháp là một đối tượng để so sánh với phiên bản này.
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ -
using System;
public class Demo {
public static void Main() {
sbyte s1 = 10;
sbyte s2 = 100;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(s2));
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Value of S1 = 10 Value of S2 = 100 Is s1 and s2 equal? = False s1 < s2
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ khác -
using System;
public class Demo {
public static void Main() {
sbyte s1 = 10;
object s2 = 10;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(s2));
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Value of S1 = 10 Value of S2 = 10 Is s1 and s2 equal? = False