结构体demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace structdemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //根据输入的年月日,提示这个日期是周几,是一年中第多少天.
            Console.WriteLine("inpyt year");
            string strYear = Console.ReadLine();
            Console.WriteLine("inpyt month");
            string strmonth = Console.ReadLine();
            Console.WriteLine("inpyt date");
            string strday = Console.ReadLine();
            Mydate mydate = new Mydate(strYear, strmonth, strday);   
            Console.WriteLine($"{strYear}-{strmonth}-{strday}是{mydate.getdayofweek()}");
            Console.WriteLine($"{strYear}-{strmonth}-{strday}是一年中第{mydate.getdayofyear()}天.");
            Console.ReadKey();

            //创建N个结构体对象,计算总成绩和平均成绩.
            List<StudentsGrade> studentsscores = new List<StudentsGrade>
            {
                new StudentsGrade("Li",90),
                new StudentsGrade("Zhang",68.5),
                new StudentsGrade("Li",78),
                new StudentsGrade("Li",86),
                new StudentsGrade("Li",99),
                new StudentsGrade("Li",48),
                new StudentsGrade("Li",77.5),
                new StudentsGrade("Li",69.5),
            };
            List<double> scores = studentsscores.Select(students => students.Fenshu).ToList();
            List<string> names = studentsscores.Select(s => s.Name).ToList();
            double sum = 0;
            foreach (var score in scores)
            {
                sum += score;
            }
            double avg = Math.Round(sum / scores.Count, 2);
            Console.WriteLine($"total scores:{sum},avg score:{avg}");
            Console.ReadKey();
        }
    }

    struct StudentsGrade
    {
        private string _name;
        private double _fenshu;
        public StudentsGrade(string name,double fenshu)
        {
            this._name = name;
            this._fenshu = fenshu;
        }

        public string Name { get => _name; set => _name = value; }
        public double Fenshu { get => _fenshu; set => _fenshu = value; }
    }

    struct Mydate
    {
        string _year;
        string _month;
        string _day;
        public Mydate(string year,string month,string day)
        {
            this._day = day;
            this._month = month;
            this._year = year;
        }

        public string getdayofweek()
        {
            DateTime then = new DateTime(int.Parse(_year), int.Parse(_month),int.Parse( _day));

            return then.DayOfWeek.ToString();
        }

        public int getdayofyear()
        {
            return new DateTime(int.Parse(_year), int.Parse(_month), int.Parse(_day)).DayOfYear;
        }
    }
}

相关推荐

  1. 结 构

    2024-03-28 16:54:01       58 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-28 16:54:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-28 16:54:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-28 16:54:01       87 阅读
  4. Python语言-面向对象

    2024-03-28 16:54:01       96 阅读

热门阅读

  1. 2024.3.25每日一题

    2024-03-28 16:54:01       46 阅读
  2. shell中的浮点类型数值如何进行比较运算

    2024-03-28 16:54:01       42 阅读
  3. python将输出保存到txt文档

    2024-03-28 16:54:01       41 阅读
  4. C# 接口 interface

    2024-03-28 16:54:01       44 阅读
  5. 【保姆级讲解Node.js常用的命令】

    2024-03-28 16:54:01       37 阅读
  6. 前端学习——nodejs篇

    2024-03-28 16:54:01       44 阅读
  7. 【无标题】

    2024-03-28 16:54:01       34 阅读
  8. 什么才是一个男人身上最大的魅力?

    2024-03-28 16:54:01       44 阅读
  9. python面试题(1~10)

    2024-03-28 16:54:01       41 阅读
  10. js的事件

    2024-03-28 16:54:01       37 阅读