C# 数组、索引器与集合的深入解析
1. 数组转换
在 C# 中,若两个数组的维度相等,且引用元素类型之间可以进行转换,就能够将一个数组转换为另一个数组。若元素可以隐式转换,则会发生隐式转换;否则,需要进行显式转换。此外,还能将派生对象数组转换为基对象数组。
示例代码
using System;
using System.Collections.Generic;
using System.Text;
namespace ConvertingArrays
{
public class Employee
{
public Employee(int empID)
{
this.empID = empID;
}
public override string ToString()
{
return empID.ToString();
}
private int empID;
}
public class Tester
{
public static void PrintArray(object[] theArray)
{
Console.WriteLine("Contents of the Array {0}", theArray.ToString());
foreach (object obj in theArray)
超级会员免费看
订阅专栏 解锁全文
6

被折叠的 条评论
为什么被折叠?



