标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Employee[] empArray = new Employee[3];
for (int i = 0; i < empArray.Length; i++)
{
empArray[i] = new Employee(i);//构造方法
}
for (int j = 0; j < empArray.Length; j++)
{
Console.WriteLine(empArray[j].ToString());
}
//第一部分
Tester t = new Tester();
t.DisplayVals(5, 6, 7, 8);//不需要生成数组,也可以传递需要的参数
int[] explicitArray = new int[5] { 1, 2, 3, 4, 5 };
t.DisplayVals(explicitArray);//第二部分
const int rows = 4; const int columns = 3;
int[,] rectangularArray = new int[rows, columns];//a个逗号就a+1维
int[][] jaggedArray1 = new int[2][] { new int[5], new int[8] }; //a个[]代表a维,2代表两行,后面的5和8代表列数
Console.WriteLine("{0}", jaggedArray1.Length);
Console.ReadLine();
}
}
}
public class Employee
{
private int empID;
public Employee(int empID)
{
this.empID = empID;
}
public override string ToString()
{
return empID.ToString();
}
}
public class Tester
{
public void DisplayVals(params int[] intVals)
{
foreach (int i in intVals)
{
Console.WriteLine("DisplayVals {0}", i);
}
}
}
标签:
原文地址:http://www.cnblogs.com/zeromaiko/p/4396592.html