当前位置:网站首页>C# 练习。类列表加记录,显示记录和清空记录
C# 练习。类列表加记录,显示记录和清空记录
2022-06-26 19:11:00 【laocooon】
using System;
namespace 仇人名单
{
internal class Program
{
static void Main(string[] args)
{
NameList nList = new NameList();
nList.Add("寒冰");
nList.Add("盖伦");
nList.Add("蜘蛛");
nList.List();//显示
nList.Add("豹女");
nList.Add("炸弹人");
nList.Add("大树");
nList.Add("女枪");
nList.Add("战争女神");
nList.Add("迅捷斥候");
nList.Add("牛头酋长");
nList.List();//显示
nList.Add("暗夜猎手");
nList.Add("不灭狂雷");
nList.Add("刀锋之影");
nList.List();//显示
nList.Clear();//清空
nList.List();//显示
Console.ReadKey();
}
}
class NameList
{
private const int MAX = 10;//最大长度
private string[] Name=new string[10];
private int cnt;//实际长度
public NameList()
{
cnt = 0;
}
public void Add(string name)//增加人员
{
if (cnt == MAX)//代表满的情况
{
//数据整体左移
for(int i=0;i<MAX-1;i++)
{
Name[i] = Name[i+1];
}
Name[MAX - 1] = name;
}
else//不满的情况
{
Name[cnt] = name;
cnt++;
}
Console.WriteLine("增加人员信息:" + name);
}
public void List()//显示所有人员
{
Console.WriteLine("显示所有人员姓名人数为:"+cnt.ToString());
for (int i = 0; i < cnt; i++)
{
Console.WriteLine(Name[i]);
}
}
public void Clear()//清空所有人员
{
Console.WriteLine("清空了列表:");
for (int i = 0; i < cnt; i++)
{
Name[i] = "";
}
cnt = 0;
}
}
}边栏推荐
- Determine whether a sequence is a stack pop-up sequence
- Tree array
- Feign remote call
- Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
- Comparing the size relationship between two objects turns out to be so fancy
- Crawl Douban to read top250 and import it into SqList database (or excel table)
- 抖音实战~分享模块~生成短视频二维码
- mysql的充值问题
- JS mobile terminal touch screen event
- SSO微服务工程中用户行为日志的记录
猜你喜欢
随机推荐
Numpy's Matplotlib
Image binarization
股票开户的具体步骤是什么?网上开户安全吗?
Comparing the size relationship between two objects turns out to be so fancy
Tiktok practice ~ sharing module ~ generate short video QR code
[recommended collection] these 8 common missing value filling skills must be mastered
Redis Basics
stm32和电机开发(直流有刷电机和步进电机)
Database SQL statement writing
Wechat applet uniapp left slide delete with Delete Icon
抖音实战~搜索页面~视频详情
数据库SQL语句撰写
Chain game development finished product source code chain game system development details
Leetcode interview question 29 clockwise print matrix
Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems
Current limiting design and Implementation
Installation and use of logstash
Feign remote call
On the escape of inequality value
成功解决之idea引用Lombok的@Slf4j后无法正常使用log









