当前位置:网站首页>C set
C set
2022-04-23 03:22:00 【C # primary advanced】
aggregate (Collection) Class is a class designed for data storage and Retrieval . These classes provide a pair of stacks (stack)、 queue (queue)、 list (list) Hash table (hash table) Support for . Most collection classes implement the same interface .
aggregate (Collection) Classes serve different purposes , Such as dynamically allocating memory for elements , Index based access to list items, etc . These classes create Object A collection of objects of a class . stay C# in ,Object Class is the base class for all data types .
- There is a known Worker Under the class :
public class Worker
{
private int age;
private string name;
private double salary;
public Worker ()
{
}
public Worker (String name, int age, double salary)
{
this.name = name;
this.age = age;
this.salary = salary;
}
public void work(){
Console.WriteLine(" full name :" + name + " Age :" + age + " Wages :" + salary + " work");
}
}
Complete the following requirements
- Create a List, stay List Add three workers to the , The basic information is as follows :
full name Age Wages
zhang3 18 300
li4 25 3500
wang5 22 3200
- stay li4 Insert a worker before , The message is : full name :zhao6, Age :24, Wages 3300
- Delete wang5 Information about
- utilize for Loop traversal , Print List Information about all workers in the
static void Main(string[] args)
{
//1.
// Complete the following requirements
//1) Create a List, stay List Add three workers to the , The basic information is as follows :
// full name Age Wages
//zhang3 18 300
//li4 25 3500
//wang5 22 3200
List<Worker> list = new List<Worker>();
Worker w1 = new Worker("zhang3", 18, 300);
Worker w2 = new Worker("li4", 25, 3500);
Worker w3 = new Worker("wang5", 22, 3200);
list.Add(w1);
list.Add(w2);
list.Add(w3);
//2) stay li4 Insert a worker before , The message is : full name :zhao6, Age :24, Wages 3300
list.Insert(1, new Worker("zhao6", 24, 3300));
//3) Delete wang5 Information about
list.RemoveAt(3);
//4) utilize for Loop traversal , Print List Information about all workers in the
for (int i = 0; i < list.Count; i++)
{
list[i].work();
}
}
3. There are the following List
List<Student> list = new List<Student>();
list.add(new Student(“Tom”, 18, 100, “class05”));
list.add(new Student(“Jerry”, 22, 70, “class04”));
list.add(new Student(“Owen”, 25, 90, “class05”));
list.add(new Student(“Jim”, 30, 80, “class05”));
list.add(new Student(“Steve”, 28, 66, “class06”));
list.add(new Student(“Kevin”, 24, 100, “class04”));
In this list On the basis of , Complete the following requirements :
1) Calculate the average age of all students
2) Calculate the average score of each class
class Student
{
public string name;
public int age;
public double score;
public string classNum;// Class number
public Student(string v1, int v2, int v3, string v4)
{
this.name = v1;
this.age = v2;
this.score = v3;
this.classNum = v4;
}
}
static void Main(string[] args)
{
//1) Calculate the average age of all students
List<Student> list2 = new List<Student>();
list2.Add(new Student("Tom", 18, 100, "class05"));
list2.Add(new Student("Jerry", 22, 70, "class04"));
list2.Add(new Student("Owen", 25, 90, "class05"));
list2.Add(new Student("Jim", 30, 80, "class05"));
list2.Add(new Student("Steve", 28, 66, "class06"));
list2.Add(new Student("Kevin", 24, 100, "class04"));
int sum = 0;
for (int i = 0; i < list2.Count; i++)
{
sum+= list2[i].age;
}
Console.WriteLine(" Average age :"+sum/list2.Count);
//2) Calculate the average score of each class
int a = 0;
double sum1 = 0;
int b = 0;
double sum2 = 0;
int c = 0;
double sum3 = 0;
for (int i = 0; i < list2.Count; i++)
{
if (list2[i].classNum =="class05")
{
sum1 += list2[i].score;
a++;
}
else if(list2[i].classNum == "class04")
{
sum2 += list2[i].score;
b++;
}
else if (list2[i].classNum == "class06")
{
sum3 += list2[i].score;
c++;
}
}
Console.WriteLine("class04 Class average :"+sum1/a);
Console.WriteLine("class05 Class average :"+sum2/b);
Console.WriteLine("class06 Class average :"+sum3/c);
}
版权声明
本文为[C # primary advanced]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621093731.html
边栏推荐
- 月薪10k-20k都无法回答的事务问题,你会吗?
- "Visual programming" test paper
- Problem a: face recognition
- . NETCORE sets the API post mode, which can accept parameters directly in parentheses
- Node configuration environment CMD does not take effect
- Problem C: realize Joseph Ring with linked list
- 关于idea调试模式下启动特别慢的优化
- Fundamentals of software testing and development
- Batch download of files ---- compressed and then downloaded
- Comprehensive calculation of employee information
猜你喜欢
2022a special equipment related management (elevator) work license question bank and simulation examination
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
MySql关键字GROUP_CONCAT,组合连接查询
Why is bi so important to enterprises?
12.<tag-链表和常考点综合>-lt.234-回文链表
How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
Top 9 task management system in 2022
TCP three handshakes and four waves
QT dynamic translation of Chinese and English languages
可以接收多种数据类型参数——可变参数
随机推荐
2022a special equipment related management (elevator) work license question bank and simulation examination
《C语言程序设计》(谭浩强第五版) 第8章 善于利用指针 习题解析与答案
全新的ORM框架——BeetlSQL介绍
Knowledge of software testing~
Fiddler use
A comprehensive understanding of static code analysis
General testing technology [1] classification of testing
Supersocket is Use in net5 - startup
MySql关键字GROUP_CONCAT,组合连接查询
Eight elder brothers chronicle [4]
Test experience data
LoadRunner - performance testing tool
Idempotency practice operation, explaining idempotency based on business
Cefsharp stores cookies and reads cookies
研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
ThreadLocal test multithreaded variable instance
The website JS in. Net core cefsharp chromium WebBrowser calls the C method in winfrom program
oracle 查询外键含有逗号分隔的数据
JS inheritance
队列的存储和循环队列