C# —— 面向对象编程练习

2023-11-03

C# —— 面向对象编程练习

基础题
在这里插入图片描述
代码如下:

class Program
    {
        static void Main(string[] args)
        {
            rectangle r = new rectangle();
            Console.WriteLine("调用不含参构造函数初始化后矩形的长为{0},宽为{1}", r.GetLength().ToString(), r.GetWidth().ToString());
            Console.WriteLine("请输入矩形长、宽:");
            rectangle R = new rectangle(float.Parse(Console.ReadLine()), float.Parse(Console.ReadLine()));
            Console.WriteLine("调用不含参构造函数初始化后矩形的长为{0},宽为{1}", R.GetLength().ToString(), R.GetWidth().ToString());
            Console.WriteLine("此矩形的周长为{0},面积为{1}", R.GetPerimeter().ToString(), R.GetArea().ToString());
            Console.WriteLine("修改矩形的长为:");
            R.ChangeLength(float.Parse(Console.ReadLine()));
            Console.WriteLine("修改矩形的宽为:");
            R.ChangeWidth(float.Parse(Console.ReadLine()));
            Console.WriteLine("修改后的矩形的周长为{0},面积为{1}", R.GetPerimeter().ToString(), R.GetArea().ToString());
        }
    }
    class rectangle
    {	
    	//私有访问。只限于本类成员访问,子类,实例都不能访问
        private float len;
        private float wid;
        //无参构造函数
        public rectangle()
        {
            this.len = 0;
            this.wid = 0;
        }
        //含参构造函数
        public rectangle(float length,float width)
        {
            this.len = length;
            this.wid = width;
        }
        //求周长
        public float GetPerimeter()
        {
            return (this.len + this.wid) * 2;
        }
        //求面积
        public float GetArea()
        {
            return this.len * this.wid;
        }
        //取矩形长度
        public float GetLength()
        {
            return this.len;
        }
        //取矩形宽度
        public float GetWidth()
        {
            return this.wid;
        }
        //修改矩形长度
        public void ChangeLength(float length)
        {
            this.len = length;
        }
        // 修改矩形宽度
        public void ChangeWidth(float width)
        {
            this.wid = width;
        }
    }

运行结果:
在这里插入图片描述
解析:

  • this代表当前类的实例对象,所以this.len 和 this.wid 都是全局变量。

在这里插入图片描述
考察点:继承,构造函数的多种方法

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Student s1 = new Student();
            s1.Display();
            Student s2 = new Student("张大磊", "男", 40, new int[] { 10, 20, 30, 40, 50 });
            s2.Display();
            Student s3 = new Student(new int[] { 60, 70, 80, 90, 100 });
            s3.Display();
        }
    }
    class Person
    {
        //保护访问。只限于本类和子类访问,实例不能访问
        protected string Name;
        protected string Sex;
        protected int Age;

        /*此处必须写一个无参构造函数。
        因为如果你的父类定义了带参数的构造函数同时没有无参重载的情况下,
        那么在子类中,你必须对父类的带参数的构造进行赋值
        */
        public Person() { }
        public Person(string name , string sex ,int age)
        {
            this.Name = name;
            this.Sex = sex;
            this.Age = age;
        }
    }

    class Student : Person
    {
        private int[] Sorce;
        //构造函数1
        public Student()
        {
            this.Name = "张磊";
            this.Sex = "男";
            this.Age = 30;
            this.Sorce = new int[] { 60, 60, 60, 60, 60 };
        }
        //构造函数2
        public Student(string name,string sex,int age,int[] sorce)
            :base(name, sex, age)//调用父类的含参构造函数
        {
            this.Sorce = sorce;
        }
        //构造函数3
        public Student(int[] sorce)
        {
            this.Name = "张小磊";
            this.Sex = "男";
            this.Age = 30;
            this.Sorce = sorce;
        }
        //求平均成绩
        public float Avg()
        {
            float sum = 0;
            foreach (int i in Sorce)
            {
                sum += i;
            }
            return sum / Sorce.Length;
        }
        public void Display()
        {
            Console.WriteLine($"姓名:{this.Name}");
            Console.WriteLine($"性别:{this.Sex}");
            Console.WriteLine($"年龄:{this.Age}");
            Console.Write("成绩:");
            foreach (int i in this.Sorce)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine($"平均成绩为:{Avg()}\n");
        }
    }

运行结果:
在这里插入图片描述
3.
(1)定义一个接口CanCry,描述会吼叫的方法public void cry()。 
(2)分别定义狗类(Dog)和猫类(Cat),实现CanCry接口。实现方法的功能分别为:打印输出“我是狗,我的叫声是汪汪汪”、“我是猫,我的叫声是喵喵喵”。 
(3)定义一个主类G,①定义一个void makeCry(CanCry c)方法,其中让会吼叫的事物吼叫。 ②在main方法中创建狗类对象(dog)、猫类对象(cat)、G类对象(g),用g调用makecry方法,让狗和猫吼叫。

考察点:接口,多继承。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Cancry dog = new Dog();
            Cancry cat = new Cat();
            G g = new G();
            g.makeCry(dog);
            g.makeCry(cat);
        }
    }
    //接口用来实现多继承是让一个类具有两个以上基类的唯一方式。
    interface Cancry
    {
        public void cry();        
    }
    class Dog : Cancry
    {
        public void cry()
        {
            Console.WriteLine("我是狗,我的叫声是汪汪汪");
        }
    }
    class Cat : Cancry
    {
        public void cry()
        {
            Console.WriteLine("我是猫,我的叫声是喵喵喵");
        }
    }
    class G
    {
        public void makeCry(Cancry c)
        {
            c.cry();
        }
    }

运行结果:
在这里插入图片描述

4.定义一个人类,包括属性:姓名、性别、年龄、国籍;包括方法:吃饭、睡觉,工作。 (1)根据人类,派生一个学生类,增加属性:学校、学号;重写工作方法(学生的工作是学习)。 (2)根据人类,派生一个工人类,增加属性:单位、工龄;重写工作方法(工人的工作是做工)。 (3)根据学生类,派生一个学生干部类,增加属性:职务;增加方法:开会。 (4)编写主函数分别对上述3类具体人物进行测试。

考点:继承,方法的重写,属性。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Student student = new Student("张磊", "男", 18, "中国", "河南大学", "s123");
            student.Work();
            Worker worker = new Worker("张小磊", "男", 28, "中国", "河南大学", 4);
            worker.Work();
            Student_cadres student_cadres = new Student_cadres("张大磊", "男", 20, "河南大学","s456", "班长");
            student_cadres.Meeting();
        }
    }
    class Person
    {
        public string Name { get;  set; } = "";
        public string Sex { get; protected set; } = "";
        public int Age { get; protected set; } = 0;
        public string Country { get; protected set; } = "";
        public virtual void Eat() { }
        public virtual void Ship() { }
        public virtual void Work() { }       
    }

    class Student : Person
    {
        public Student() { }
        public Student(string name,string sex,int age ,string country,string school,string stu_num)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            School = school;
            Stu_Num = stu_num;
        }
        public string School { get; protected set; } = "";
        public string Stu_Num { get; protected set; } = "";
        public override void Work()
        {
            Console.WriteLine($"{Name}是{School}{Age}岁的{Country}{Sex}学生,{Name}的学号是{Stu_Num}。{Name}有好好学习哦\n");
        }
    }

    class Worker: Person
    {
        public Worker(string name, string sex, int age, string country, string company, int working_years)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            Company = company;
            Working_years = working_years;
        }
        public string Company { get; protected set; } = "";
        public int Working_years { get; protected set; } = 0;
        public override void Work()
        {
            Console.WriteLine($"{Name}是{Company}{Age}岁的{Country}{Sex}工人,{Name}的工龄是{Working_years}。{Name}工作超努力的哦\n");
        }
    }

    class Student_cadres : Student
    {
        public Student_cadres(string name, string sex, int age, string country, string stu_num, string post)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            Stu_Num = stu_num;
            Post = post;
        }
        public string Post { get; protected set; } = "";
        public void Meeting()
        {
            Console.WriteLine($"{Name}是{School}{Age}岁的{Country}{Sex}学生,{Name}的学号是{Stu_Num},职务是{Post}。{Name}有认真开会哦\n");
        }
    }

运行结果:
在这里插入图片描述

5.Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:double getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。

SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数

SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率

BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。

写一个程序,把若干各种类型的员工放在一个Employee数组里,
写一个方法,打印出某月每个员工的工资数额。
注意:要求把每个类都做成完全封装,不允许非私有化属性。

考察点:抽象,私有化属性。

代码如下:

class Program
    {   
        public void PrintSalary(Employee[] woker)
        {
            Console.Write("请输入现在的月份:");
            int month = int.Parse(Console.ReadLine());
            for (int i = 0; i < woker.Length; i++)
            {
                Console.WriteLine($"我是{woker[i].GetName()},我在{month}月的工资是{woker[i].getSalary(month)}\n");
            }
        }
        static void Main(string[] args)
        {
            SalariedEmployee employee1 = new SalariedEmployee("张磊",1,5000);
            HourlyEmployee employee2 = new HourlyEmployee("张小磊", 2, 20, 200);
            SalesEmployee employee3 = new SalesEmployee("张大磊", 3, 10000, 0.7);
            BasePlusSalesEmployee emloyee4 = new BasePlusSalesEmployee("张磊磊", 4, 5000, 0.7, 3000);

            Employee[] woker = { employee1, employee2, employee3, emloyee4 };
            Program p = new Program();
            p.PrintSalary(woker);
        }
    }
    abstract class Employee
    {
        private string Name { get; set; } = "";
        private int BirthMonth { get; set; } = 0;
        public void SetName(string name)
        {
            Name = name;
        }
        public void SetBirthMonth(int birthmonth)
        {
            BirthMonth = birthmonth;
        }
        public string GetName()
        {
            return Name;
        }
        public int GetBirthMonth()
        {
            return BirthMonth;
        }
        public abstract double getSalary(int month) ;
    }

    class SalariedEmployee : Employee
    {
        private int Monthly_Salary { get; set; } = 0;
        public SalariedEmployee (string name,int birthmonth,int monthly_salary)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Monthly_Salary = monthly_salary;
        }
        public override double getSalary(int month)
        {
            if (GetBirthMonth() == month)
            {
                return Monthly_Salary + 100;
            }
            else
                return Monthly_Salary;
        }
    }

    class HourlyEmployee : Employee
    {
        private int Hourly_Salary { get; set; } = 0;
        private int Hour { get; set; } = 0;
        public HourlyEmployee(string name, int birthmonth, int hourly_salary,int hour)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Hourly_Salary = hourly_salary;
            Hour = hour;
        }
        public override double getSalary(int month)
        {
            double money = 0;
            if (Hour > 160)
            {
                money = 160 * Hourly_Salary + (Hour - 160) * Hourly_Salary * 1.5;
            }
            else
                money = Hourly_Salary * Hour;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }
    }

    class SalesEmployee : Employee
    {
        private int Monthly_Sales { get; set; } = 0;
        private double Royalty_Rate { get; set; } = 0;
        public int GetMonthly_Sales() { return Monthly_Sales; }
        public double GetRoyalty_Rate() { return Royalty_Rate; }
        public SalesEmployee() { }
        public SalesEmployee(string name, int birthmonth,int monthly_slaes,double royalty_rate)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Monthly_Sales = monthly_slaes;
            Royalty_Rate = royalty_rate;
        }
        public override double getSalary(int month)
        {
            double money = Monthly_Sales * Royalty_Rate;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }
    }

    class BasePlusSalesEmployee : SalesEmployee
    {
        private int Base_Salary { get; set; } = 0;
        public BasePlusSalesEmployee(string name, int birthmonth, int monthly_slaes, double royalty_rate, int base_salary)
            :base(name,birthmonth,monthly_slaes,royalty_rate)
        {
            Base_Salary = base_salary;
        }
        public override double getSalary(int month)
        {
            double money = GetMonthly_Sales() * GetRoyalty_Rate() + Base_Salary;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }

    }

运行结果:
在这里插入图片描述
解析:
本题特殊点在于要求属性全是私有的,那么子类想要修改和获取父类的属性时就需要通过父类的Get()和Set()函数来进行操作。

6.图书买卖类库,该系统中必须包括三个类,类名及属性设置如下。
图书类(Book)

  • 图书编号(bookId)
  • 图书名称(bookName)
  • 图书单价(price)
  • 库存数量(storage)

订单项类(OrderItem)

  • 图书名称(bookName)
  • 图书单价(price)
  • 购买数量(num)

订单类(Order):

  • 订单号(orderId)
  • 订单总额(total)
  • 订单日期(date)
  • 订单项列表(items)

具体要求及推荐实现步骤
1、创建图书类,根据业务需要提供需要的构造方法和setter/getter方法。
2、创建订单项类,根据业务需要提供需要的构造方法和setter/getter方法。
3、创建订单类,根据业务需要提供需要的构造方法和setter/getter方法。
4、创建测试类Test,实现顾客购买图书。
A、获取所有图书信息并输出:创建至少三个图书对象并输出即可。
B、顾客购买图书:顾客通过输入图书编号来购买图书,并输入购买数量。
C、输出订单信息:包括订单号、订单明细、订单总额、订单日期。

考察点:类之间的相互协同

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Book book1 = new Book(1, "Java教程", 30.6, 30);
            Book book2 = new Book(2, "JSP 指南", 42.1, 40);
            Book book3 = new Book(3, "SSH 架构", 47.3, 15);
            Book[] book = { book1, book2, book3 };
            Test test = new Test();
            test.BookItem(book);
            Order order = new Order();
            test.PrintBookItems(test.Buy(book), order);
        }
    }
    class Test
    {
        public void BookItem(Book[] book)
        {
            Console.WriteLine("\t图书列表");
            Console.WriteLine(string.Format(
                    "{0,-10}{1,-10}{2,-10}{3,5}",
                    "图书编号", "图书名称", "图书单价", "库存数量"));
            Console.WriteLine("--------------------------------------------------");
            for (int i = 0; i < book.Length; i++)
            {
                Console.WriteLine($"{book[i].GetBookId()}\t{book[i].GetBookName()}\t{book[i].GetPrice()}\t{book[i].GetStock()}");
            }
            Console.WriteLine("--------------------------------------------------");
        }
        public List<OrderItem> Buy(Book[] book)
        {
            List<OrderItem> OrderItemList = new List<OrderItem>();
            int i = 1;
            while (i <= 3)
            {
                i++;
                Console.Write("请输入图书编号选择图书:");
                int bookid = int.Parse(Console.ReadLine())-1;
                Console.Write("请输入购买图书的数量:");
                int num = int.Parse(Console.ReadLine());
                Console.WriteLine("请继续购买图书。");
                OrderItemList.Add(new OrderItem(num, book[bookid].GetBookName(), book[bookid].GetPrice()));
            }
            return OrderItemList;
        }
        public void PrintBookItems(List<OrderItem> OrderItemList, Order order)
        {
            Console.WriteLine("\n\t图书订单");
            Console.WriteLine($"图书订单号:{order.GetOrderId()}");
            Console.WriteLine(string.Format("{0,-10}{1,-10}{2,-10}", "图书名称", "购买数量", "图书单价"));
            Console.WriteLine("---------------------------------");
            order.PrintItems(OrderItemList);
            Console.WriteLine("---------------------------------");
            Console.WriteLine($"订单总额:\t\t\t{order.GetTotal(OrderItemList)}");
            Console.WriteLine($"日期:{order.GetData()}");
        }
    }
    class Book
    {
        private int BookId { get; set; } = 0;
        private string BookName { get; set; } = "";
        private double Price { get; set; } = 0;
        private int Stock { get; set; } = 0;
        public Book(int bookid, string bookname, double price, int stock)
        {
            BookId = bookid;
            BookName = bookname;
            Price = price;
            Stock = stock;
        }
        public void SetStock(int stock)
        {
            Stock = stock;
        }
        public void SetPrice(double price)
        {
            Price = price;
        }
        public int GetBookId()
        {
            return BookId;
        }
        public string GetBookName()
        {
            return BookName;
        }
        public double GetPrice()
        {
            return Price;
        }
        public int GetStock()
        {
            return Stock;
        }
    }

    class OrderItem
    {
        private int Num { get; set; } = 0;
        private string BookName { get; set; } = "";
        private double Price { get; set; } = 0;
        public OrderItem(int num, string bookname, double price)
        {
            Num = num;
            BookName = bookname;
            Price = price;
        }
        public void SetNum(int num)
        {
            Num = num;
        }
        public int GetNum()
        {
            return Num;
        }
        public string GetBookName()
        {
            return BookName;
        }
        public double GetPrice()
        {
            return Price;
        }
    }

    class Order
    {
        private string OrderId = "00001";
        private double Total { get; set; } = 0;
        private string Data = DateTime.Now.ToString();
        private string Items { get; set; } = "";
        public double GetTotal(List<OrderItem> OrderItemList)
        {
            foreach (var orderitem in OrderItemList)
            {
                Total += orderitem.GetNum() * orderitem.GetPrice();
            }
            return Total;
        }
        public string GetData()
        {
            return Data;
        }
        public void PrintItems(List<OrderItem> OrderItemList)
        {
            foreach (var orderitem in OrderItemList)
            {
                Console.WriteLine($"{orderitem.GetBookName()}\t{orderitem.GetNum()}\t{orderitem.GetPrice()}");
            }
        }
        public string GetOrderId() { return OrderId; }


    }

运行结果:
在这里插入图片描述
解析:
感觉这道题没用多少类的知识,但是写完感觉对函数用法更加深刻了。建议闲了动手写写,还挺好玩的。

7.在这里插入图片描述
考察点:虚方法的实现,二维数组。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入本次评优的学生数量:");
            string[,] s = new string[int.Parse(Console.ReadLine()),2];
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Console.Write("请输入学生姓名:");
                s[i, 0] = Console.ReadLine();
                Console.Write("请输入学生的成绩:");
                s[i, 1] = Console.ReadLine();
                Console.WriteLine();
            } 
            Console.Write("请输入本次评优的老师数量:");
            string[,] t = new string[int.Parse(Console.ReadLine()),2];
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Console.Write("请输入老师姓名:");
                t[i, 0] = Console.ReadLine();
                Console.Write("请输入老师的论文数量:");
                t[i, 1] = Console.ReadLine();
                Console.WriteLine();
            }
            Console.WriteLine("----优秀学生榜----");
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Student student = new Student(s[i, 0].ToCharArray(), int.Parse(s[i, 1]));
                if (student.Isgood() == 1)
                    Console.WriteLine(student.print());
            }

            Console.WriteLine("\n----优秀老师榜----");
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Teacher teacher = new Teacher(t[i, 0].ToCharArray(), int.Parse(t[i, 1]));
                if (teacher.Isgood() == 1)
                    Console.WriteLine(teacher.print());
            }
        }
        class Base
        {
            protected char[] Name = new char[8];
            protected int Num;
            public Base() { }
            public Base(char[] name)
            {
                Name = name;
            }
            public string print()
            {
                return $"我是{string.Join("",Name)},我的成果是{Num}(分/篇),所以我很优秀哦!";
            }
            public virtual int Isgood() { return 0; }
        }
        class Student : Base
        {
            public Student(char[] name,int num)
                :base(name)
            {
                Num = num;
            }
            public override int Isgood()
            {
                if (Num > 90)
                    return 1;
                else
                    return 0;
            }
        }
        class Teacher : Base
        {
            public Teacher(char[] name,int num)
                :base (name)
            {
                Num = num;
            }
            public override int Isgood()
            {
                if (Num > 3)
                    return 1;
                else
                    return 0;
            }
        }
    }

运行结果:
在这里插入图片描述
8.在这里插入图片描述
在这里插入图片描述在这里插入图片描述
基础题不难。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Triangle tri = new Triangle(1, 1, 4, 1, 4, 5);
            tri.f();
            tri.Print();
        }
    }
    class Point
    {
        protected int x1 { get; set; } = 0;
        protected int y1 { get; set; } = 0;
        public Point() { }
        public Point(int a ,int b)
        {
            x1 = a;
            y1 = b;
        }
    }

    class Line : Point
    {
        protected int x2 { get; set; } = 0;
        protected int y2 { get; set; } = 0;
        public Line() { }
        public Line(int a,int b,int c,int d)
            :base(a, b)
        {
            x2 = c;
            y2 = d;
        }
    }

    class Triangle : Line
    {
        private int x3 { get; set; } = 0;
        private int y3 { get; set; } = 0;
        private double area { get; set; } = 0;
        public Triangle(int a, int b, int c, int d, int e,int f)
            :base(a, b, c, d)
        {
            x3 = e;
            y3 = f;
        }
        public void f()
        {
            double x = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            double y = Math.Sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
            double z = Math.Sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
            double s = (x + y + z) / 2;
            area = Math.Sqrt(s * (s - x) * (s - y) * (s - z));
        }
        public void Print()
        {
            Console.WriteLine($"({x1},{y1})\t({x2},{y2})\t({x3},{y3})");
            Console.WriteLine($"area = {area}");
        }
    }

运行结果:
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C# —— 面向对象编程练习 的相关文章

  • C++:头文件中全局函数的多重定义错误

    该函数是全局的 在头文件中定义 暂时地我想把它留在那里 头文件还构成一个具有内联函数的特定类 其中一个函数调用this全局函数 源文件不包含任何有问题的全局函数 有关错误原因的任何提示吗 如果有人感兴趣的话我可以发布代码 mainwindo
  • 语言混合:模型和视图

    考虑开发一个应用程序 其中模型将使用 C 使用 Boost 编写 视图将使用 Objective C 使用 Cocoa Touch 编写 哪里有一些示例展示了如何集成 C 和 Objective C 来开发 iPhone 应用程序 直接从源
  • 在两个 .cpp 文件之间定义全局变量 [重复]

    这个问题在这里已经有答案了 如何在 A cpp 和 B cpp 之间共享 全球化 bool 变量 其中它们都不包含其他 h 文件 他们有其他联合头文件 但彼此没有 我可以在这些共享标头中定义全局变量吗 Thanks 我可以在这些共享标头中定
  • 实体框架中的重复键异常?

    我试图捕获当我将具有给定用户名的现有用户插入数据库时 引发的异常 正如标题所说 我正在使用 EF 当我尝试将用户插入数据库时 引发的唯一异常是 UpdateException 如何提取此异常以识别其是否是重复异常或其他异常 catch Up
  • WPF - 按多列排序时使用自定义比较器

    我有一个 ListView GridView 我想按 2 列排序 因此如果第 1 列中有 2 个以上的项目具有相同的值 它将按第 2 列排序 非常简单 但是在对 A Z 进行排序时 空字符串会出现在顶部 我想把它们移到底部 我制作了一个比较
  • C# ConfigurationManager 从 app.config 检索错误的连接字符串

    我有一个简单的 WinForms 应用程序 它最终将成为一个游戏 现在 我正在研究它的数据访问层 但遇到了障碍 我创建了一个单独的项目 名为DataAccess在其中 我创建了一个本地 mdfSQL Server 数据库文件 我还创建了一个
  • 未定义异常变量时通过引用捕获

    捕获异常时 标准指导是按值抛出 按引用捕获 据我了解 这有两个原因 如果由于内存不足异常而引发异常 我们将不会调用可能终止程序的复制构造函数 如果异常是继承层次结构的一部分 我们可能会对异常进行对象切片 如果我们有一个场景 我们没有在 ca
  • 从 ef core 的子集合中删除一些项目

    我有一个父表和子表 其中父表与子表具有一对多关系 我想删除一些子项 并且希望父项的子集合反映该更改 如果我使用删除选定的子项RemoveRange 那么子集合不会更新 如果我使用Remove从子集合中删除子集合然后 显然 它不如使用效率高R
  • 使用对象列表构建树

    我有一个带有属性 id 和parent id 的对象列表 我想建造一棵树来连接那些孩子和父母 1 个父对象可以有多个子对象 并且有一个对象将成为所有对象的祖先 实现该功能最快的算法是什么 我使用 C 作为编程语言 但其他语言也可以 像这样的
  • AspNetCore.SignalR:无法启动未处于初始状态的连接

    我无法让 ASP NET Core SignalR 应用程序正常运行 我有这个服务器端代码 public class PopcornHub Hub private int Users public async Task BroadcastN
  • ASP.NET Web API Swagger(Swashbuckle)重复OperationId

    I have a web api controller like below In swagger output I am having the below image And when I want to consume it in my
  • 打破条件变量死锁

    我遇到这样的情况 线程 1 正在等待条件变量 A 该变量应该由线程 2 唤醒 现在线程 2 正在等待条件变量 B 该变量应该由线程 1 唤醒 在我使用的场景中条件变量 我无法避免这样的死锁情况 我检测到循环 死锁 并终止死锁参与者的线程之一
  • 语义问题 Qt Creator:命名空间“std”中没有名为“cout”的成员

    我开始使用 Qt Creator 编写代码 对于 C 文件 我遇到很多语义问题 99 是 命名空间 yyy 中没有名为 xxx 的成员cpp文件构建 编译和输出没有问题 如果我点击例如cout 我已链接到 iostream 我是否需要在 Q
  • 如果数组为空,LINQ 返回 null

    public class Stuff public int x other stuff 我有一个IEnumerable
  • fscanf 和 EOF 中的否定扫描集

    我的文件中有一个以逗号分隔的字符串列表 姓名 1 姓名 2 姓名 3 我想跳过所有逗号来阅读这些名字 我写了以下循环 while true if fscanf file my string 1 break 然而 它总是比预期多执行一次 给定
  • 使 C# 编译器相信执行将在成员返回后停止

    我认为目前这是不可能的 或者这是否是一个好主意 但这是我刚才正在考虑的事情 我使用 MSTest 对我的 C 项目进行单元测试 在我的一项测试中 我执行以下操作 MyClass instance try instance getValue
  • 如何在Linux上构建GLFW3项目?

    我已经使用 cmake 和 make 编译了 glfw3 和包含的示例 没有出现任何问题 开始编写我的第一个项目 作为 opengl 和 glfw 的新手 并且对 C 和 CMake 没有经验 我正在努力理解示例构建文件 甚至要链接哪些库和
  • 为什么从绑定返回的对象会忽略额外的参数?

    假设我有一个带有两个参数的函数 void f int x int y 我想绑定其中之一 我可以用std bind如下 auto partiallyBoundF std bind f 10 1 partiallyBoundF仅需要一个参数 但
  • 无效的模板相关成员函数模板推导 - 认为我正在尝试使用 std::set

    我有一个继承自基类模板的类模板 基类模板有一个数据成员和一个成员函数模板 我想从我的超类中调用它 我知道为了消除对成员函数模板的调用的歧义 我必须使用template关键字 我必须明确引用this在超级班里 this gt base mem
  • 如何设置 Swashbuckle 与 Microsoft.AspNetCore.Mvc.Versioning

    我们有asp net core webapi 我们添加了Microsoft AspNetCore Mvc Versioning and Swashbuckle拥有招摇的用户界面 我们将控制器指定为 ApiVersion 1 0 Route

随机推荐

  • 页面结构分析

  • 关于解决Win10家庭中文版没有组策略编辑器的问题

    今天在使用远程桌面连接服务器的时候发生了一些列的问题 首先是突然间出现了凭据不工作问题 但自己的用户名及密码都没有错误 最后查询发现需要修改在凭据管理中修改相应信息 呢么修改则需要在组策略编辑器中修改 但是呢win10家庭版又无法进入 以下
  • 【华为OD机试真题 python】最大数字【2023 Q1

    题目描述 最大数字 给定一个由纯数字组成以字符串表示的数值 现要求字符串中的每个数字最多只能出现2次 超过的需要进行删除 删除某个重复的数字后 其它数字相对位置保持不变 如 34533 数字3重复超过2次 需要删除其中一个3 删除第一个3后
  • idea读取数据库乱码,Navicat正常(解决)

    乱码问题困扰了我2天 菜的抠脚 先说说问题吧 你如果不想看这些废话就直接去下面解决 我先创建了数据库 拷贝了sql语句运行之后 Navicat正常显示 但是页面显示乱码 其实是中文latin1编码 debug跟进程序 发现在hibernat
  • msvcp140_1.dll丢失怎样修复?快速修复dll文件缺失

    msvcp140 1 dll丢失怎样修复 关于msvcp140 1 dll丢失 其实和其他dll文件的修复方法是一模一样的 你缺失了什么dll文件 那么你就在百度搜索这个dll文件 然后放到指定的文件夹就好了 解决起来还是非常的简单的 ms
  • Cocos Creator资源管理AssetManager细说一二

    关于AssetManager Asset Manager 是 Creator 在 v2 4 新推出的资源管理器 用于替代之前的 cc loader 新的 Asset Manager 资源管理模块具备加载资源 查找资源 销毁资源 缓存资源 A
  • VUE搭建项目,配置本地IP地址其他人可访问项目(整理)

    1 首先找到config文件夹目录下的 index js文件 Various Dev Server settings host localhost 将localhost进行替换成 0 0 0 0 host 0 0 0 0 can be ov
  • 如何使用USB接口对C51单片机下载固件

    使用USB转UART芯片对单片机下载固件时会遇到的问题 C51系列单片机在下载固件的时候需要断电重启 在使用RS232接口的时候不会遇到什么困难 因为RS232不需要进行识别 但是现在使用USB转UART的芯片时会遇到问题 因为USB设备在
  • CIFAR-10训练模型(ResNet18)

    1 搭建环境 环境在实验进行时已经搭建完毕 具体步骤就不过多赘述 参考 https blog csdn net weixin 39574469 article details 117454061 接下来只需导入所需的包即可 import n
  • python中列表数据汇总和平均值_如何从记录列表中计算平均值

    所以我正在做一个作业 当从一个数据列表中计算一个平均值 数据是从一个外部的 txt文件中读取的 时 我似乎遇到了麻烦 具体来说 我要做的是从下面的数据列表中读取数据记录 在1 2 2014 Frankton 42305 67 23 12 4
  • 高德地图API INVALID_USER_SCODE问题以及keystore问题

    转载地址 http m blog csdn net article details id 50448014 请尊重原创 今天这篇文章会给大家介绍三个问题 1 接入API时出现invalid user scode问题 首先进行第一个大问题 接
  • python连接数据库设置编码_python连接mysql数据库——编码问题

    编码问题 1 连接数据库语句 在利用pycharm连接本地的mysql数据库时 要考虑到的是将数据库语句填写完整 困扰了一下午的问题就是连接语句并没有加入编码设置 db pymysql connect host localhost user
  • 如何利用计算机打印较大的字,如何在一张A4纸上打印一个超大字?

    是不是很想打印超大字 要是硬件上去了 就什么话也不用说了 可惜的是 手中只有一个A4的打印机 怎么办 还是有办法的 用Microsoft Office 2003就可以 我由于学校工作的原因 打印机只能打A4的纸 有时又想打超大字 不得不用现
  • TensorFlow零基础入门,实现手写数字识别

    TensorFlow 是一个用于人工智能的开源神器 主要为深度学习算法提供了很多函数 以及独特的运算支持 废话不多说直接上干货 我的环境 python3 7 tensorflow 1 13 2 numpy 1 20 2 1 入门示例 imp
  • 算法分享三个方面学习方法(做题经验,代码编写经验,比赛经验)

    目录 0 前言 遇到OI不要慌 只要道路对了 就不怕遥远 1 做题经验谈 1 1 做题的目的 1 2 我对于算法比赛的题目的看法 1 2 1 类似题 1 2 2 套模型 1 3 在训练过程中如何做题 1 4 一些建议 提高算法能力 1 5
  • AJAX分页以及IFRAME载入

    AJAX获取数据并分页显示 ul class movList ul div div
  • leetcode-03. 数组中重复的数字刷题笔记(c++)

    写在前面 难度 简单 unordered map 或 sort排序 大数组方法异常溢出 数据量 小数据量 数组元素作为下标 大数据量 无需map映射 耗费空间 sort排序 前后元素是否等值 题目详情 找出数组中重复的数字 在一个长度为 n
  • 一条慢SQL引发的改造

    前言 闲鱼服务端在做数据库查询时 对每一条SQL都需要仔细优化 尽可能使延时更低 带给用户更好的体验 但是在生产中偶尔会有一些情况怎么优化都无法满足业务场景 本文通过对一条慢SQL的真实改造 介绍解决复杂查询的一种思路 以及如何使得一条平均
  • Seata 处理分布式事务

    文章目录 1 Seata 简介2 2 Seata的安装 2 1 修改配置文件 2 2 在nacos上创建配置文件 seataServer yaml 2 3 安装路径seata seata server 1 6 0 seata script
  • C# —— 面向对象编程练习

    C 面向对象编程练习 基础题 代码如下 class Program static void Main string args rectangle r new rectangle Console WriteLine 调用不含参构造函数初始化后