检查一个数组对象是否等于C#中的另一个数组对象
要检查一个数组对象是否等于另一个数组对象,代码如下:
示例
using System;
public class Demo {
public static void Main(){
String[] strArr1 = new String[3] { "John", "Jacob", "Tim"};
String[] strArr2 = new String[3] { "Tom","Brad","Bradley"};
Console.WriteLine("First String array...");
foreach(string val in strArr1){
Console.WriteLine(val);
}
Console.WriteLine("Second String array...");
foreach(string val in strArr2){
Console.WriteLine(val);
}
Console.WriteLine("Are both the array objects equal? = "+strArr1.Equals(strArr2));
}
}输出结果
这将产生以下输出-
First String array... John Jacob Tim Second String array... Tom Brad Bradley Are both the array objects equal? = False
示例
让我们看另一个例子-
using System;
public class Demo {
public static void Main(){
int[] arr1 = new int[5] { 10, 20, 30, 40, 50};
int[] arr2 = new int[5] { 25, 25, 40, 55, 70};
Console.WriteLine("First integer array...");
foreach(int val in arr1){
Console.WriteLine(val);
}
Console.WriteLine("Second integer array...");
foreach(int val in arr2){
Console.WriteLine(val);
}
arr1 = arr2;
Console.WriteLine("Are both the array objects equal? = "+arr1.Equals(arr2));
}
}输出结果
这将产生以下输出-
First integer array... 10 20 30 40 50 Second integer array... 25 25 40 55 70 Are both the array objects equal? = True
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短