第四次作业

本文介绍了如何在C#中创建一个包含员工ID属性的Employee类,并通过构造方法初始化实例。此外,展示了如何使用Test类的DisplayVals方法,既可以接收整数数组参数,也可以直接传递整数参数。最后,通过生成不同维度的数组来展示数组的创建和使用。

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);
}
}
}

转载于:https://www.cnblogs.com/zeromaiko/p/4396592.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值