当前位置: 首页 > news >正文

C#面对对象(英雄联盟人物管理系统)

目录

英雄信息类

因为要在两个窗体里面调用字典,所以要写两个类来构建全局变量

 添加功能

 查询功能


英雄信息类

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

namespace WindowsFormsApplication1
{
  public  class hero
    {
      public int Id;
      public string Name;
      public int Money;
      public string Type;
      public hero(int id,string name,int money,string type) {
          Id = id;
          Name = name;
          Money = money;
          Type = type;
      }
    }
}

因为要在两个窗体里面调用字典,所以要写两个类来构建全局变量

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

namespace WindowsFormsApplication1
{

    internal class Class1
    {
        public Dictionary<string ,hero > dic;

        public Class1()
        {
            dic = new Dictionary<string, hero>();
        }
    }
}

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

namespace WindowsFormsApplication1
{
    class Class2
    {

        public static Class1 data = new Class1();
    }
}
 

 添加功能

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int id = int.Parse(textBox1.Text);
            string name = textBox2.Text;
            int money = int.Parse(textBox3.Text);
            string object1 = textBox4.Text;
            hero h = new hero(id, name, money, object1);
            Class2.data.dic[name] = h;
           
            // int s = Class2.data.dic[name].Money;
          //  MessageBox.Show(s.ToString());

        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
 

 查询功能

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

        }
       
        private void button2_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ShowDialog();
            NewMethod();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            NewMethod();
        }

        private void NewMethod()
        {
            this.dataGridView1.Rows.Clear();

            for (int i = 0; i < Class2.data.dic.Keys.Count; i++)
            {
                string nam = Class2.data.dic.Keys.ElementAt(i);

                hero h = Class2.data.dic[nam];
                DataGridViewRow row = new DataGridViewRow();

                row.CreateCells(dataGridView1);
                row.Cells[0].Value = h.Id;
                row.Cells[1].Value = h.Name;
                row.Cells[2].Value = h.Money;
                row.Cells[3].Value = h.Type;
                dataGridView1.Rows.Add(row);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text=="")
            {
                  NewMethod();
            }
            else
            {
                this.dataGridView1.Rows.Clear();
                string name = textBox1.Text;

                for (int i = 0; i < Class2.data.dic.Keys.Count; i++)
                {
                    string nam = Class2.data.dic.Keys.ElementAt(i);
                    if (nam==name)
                    {
                        hero h = Class2.data.dic[nam];
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView1);
                        row.Cells[0].Value = h.Id;
                        row.Cells[1].Value = h.Name;
                        row.Cells[2].Value = h.Money;
                        row.Cells[3].Value = h.Type;
                        dataGridView1.Rows.Add(row);
                    }                 
                }
            }
        }     
    }
}
 

相关文章:

C#面对对象(英雄联盟人物管理系统)

目录 英雄信息类 因为要在两个窗体里面调用字典&#xff0c;所以要写两个类来构建全局变量 添加功能 查询功能 英雄信息类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WindowsFormsApp…...

2023年中国分布式光纤传感产量、需求量及行业市场规模分析[图]

分布式光纤传感器中的光纤能够集传感、传输功能于一体&#xff0c;能够完成在整条光纤长度上环境参量的空间、时间多维连续测量&#xff0c;具有结构简单、易于布设、性价比高、易实现长距离等独特优点&#xff0c;常用的分布式光纤传感器有光时域反射仪、布里渊分析仪、喇曼反…...

B2R Raven: 2靶机渗透

B2R Raven: 2靶机渗透 视频参考&#xff1a;ajest &#xff1a;https://www.zhihu.com/zvideo/1547357583714775040?utm_id0 原文参考&#xff1a;ajest &#xff1a;https://zhuanlan.zhihu.com/p/270343652 文章目录 B2R Raven: 2靶机渗透1 启动靶机&#xff0c;查看后网卡…...

SpringBoot-黑马程序员-学习笔记(六)

目录 76.常用计量单位使用 77.bean属性校验 81.测试表现层 82.发送虚拟请求 94.springboot读写redis的客户端 100.ElasticSearch&#xff08;简称ES&#xff09; 一个分布式全文搜索引擎 76.常用计量单位使用 Data Component ConfigurationProperties(prefix "serve…...

unity2022版本 实现手机虚拟操作杆

简介 在许多移动游戏中&#xff0c;虚拟操纵杆是一个重要的用户界面元素&#xff0c;用于控制角色或物体的移动。本文将介绍如何在Unity中实现虚拟操纵杆&#xff0c;提供了一段用于移动控制的代码。我们将讨论不同类型的虚拟操纵杆&#xff0c;如固定和跟随&#xff0c;以及如…...

『GitHub Actions』部署静态博客指南

前言 之前博主是使用的 Jenkins 实现 vuepress 博客的自动部署与持续交付&#xff0c;但是因为现在迁移服务器到海外&#xff0c;并且服务器配置降低。现在经常出现服务器的 Jenkins 构建过程中 CPU 占用率过高&#xff0c;导致服务器卡死 然后我想的话既然只是部署静态博客&…...

WPF Datagrid Header数据绑定,表头复选框实现全选、全否、部分选中,根据条目动态变化

制作一个根表头为CheckBox可全选、全不选的列表&#xff0c;且可根据条目自动调整CheckBox的状态&#xff08;选中、不选、部分选中&#xff09;。 本来是想用DataGrid做一个CheckBox的列用于勾选其中的某些行&#xff0c;当时做出来之后想着添加一个全选、全否的功能。做两个…...

Tensorflow2 中对模型进行编译,不同loss函数的选择下输入数据格式需求变化

一、tf2中常用的损失函数介绍 在 TensorFlow 2 中&#xff0c;编译模型时可以选择不同的损失函数来定义模型的目标函数。不同的损失函数适用于不同的问题类型和模型架构。下面是几种常见的损失函数以及它们的作用和适用场景&#xff1a; 1.均方误差&#xff08;Mean Squared …...

【python】基础语法(三)--异常、模块、包

异常 代码中出现的报错问题&#xff0c;可能会导致整个代码的停止&#xff0c;为了避免这种情况&#xff0c;有了捕获异常操作&#xff1b; 捕获异常 提前预知可能出错的代码&#xff0c;做好准备&#xff0c;避免因bug导致整个项目停止&#xff1b; try&#xff1a;可能出…...

XGBoost+LR融合

1、背景简介 xgboostlr模型融合方法用于分类或者回归的思想最早由facebook在广告ctr预测中提出&#xff0c;其论文Practical Lessons from Predicting Clicks on Ads at Facebook有对其进行阐述。在这篇论文中他们提出了一种将xgboost作为feature transform的方法。大概的思想…...

leetcode:1929. 数组串联(python3解法)

难度&#xff1a;简单 给你一个长度为 n 的整数数组 nums 。请你构建一个长度为 2n 的答案数组 ans &#xff0c;数组下标 从 0 开始计数 &#xff0c;对于所有 0 < i < n 的 i &#xff0c;满足下述所有要求&#xff1a; ans[i] nums[i]ans[i n] nums[i] 具体而言&am…...

Epoch和episodes的区别

“Epoch” 和 “episode” 是两个不同的概念&#xff0c;通常在不同领域中使用。 Epoch&#xff08;周期&#xff09;&#xff1a; Epoch 是一个在机器学习和深度学习中常用的术语&#xff0c;通常用于表示训练数据集中的一个完整遍历。在每个 epoch 中&#xff0c;整个训练数据…...

漏洞复现--华测监测预警系统2.2任意文件读取

免责声明&#xff1a; 文章中涉及的漏洞均已修复&#xff0c;敏感信息均已做打码处理&#xff0c;文章仅做经验分享用途&#xff0c;切勿当真&#xff0c;未授权的攻击属于非法行为&#xff01;文章中敏感信息均已做多层打马处理。传播、利用本文章所提供的信息而造成的任何直…...

数据结构 - 6(优先级队列(堆)13000字详解)

一&#xff1a;堆 1.1 堆的基本概念 堆分为两种&#xff1a;大堆和小堆。它们之间的区别在于元素在堆中的排列顺序和访问方式。 大堆&#xff08;Max Heap&#xff09;&#xff1a; 在大堆中&#xff0c;父节点的值比它的子节点的值要大。也就是说&#xff0c;堆的根节点是堆…...

Js高级技巧—拖放

拖放基本功能实现 拖放是一种非常流行的用户界面模式。它的概念很简单&#xff1a;点击某个对象&#xff0c;并按住鼠标按钮不放&#xff0c;将 鼠标移动到另一个区域&#xff0c;然后释放鼠标按钮将对象“放”在这里。拖放功能也流行到了 Web 上&#xff0c;成为 了一些更传统…...

ELF和静态链接:为什么程序无法同时在Linux和Windows下运行?

目录 疑问 编译、链接和装载&#xff1a;拆解程序执行 ELF 格式和链接&#xff1a;理解链接过程 小结 疑问 既然我们的程序最终都被变成了一条条机器码去执行&#xff0c;那为什么同一个程序&#xff0c;在同一台计算机上&#xff0c;在 Linux 下可以运行&#xff0c;而在…...

【爬虫实战】python微博热搜榜Top50

一.最终效果 二.项目代码 2.1 新建项目 本文使用scrapy分布式、多线程爬虫框架编写的高性能爬虫&#xff0c;因此新建、运行scrapy项目3步骤&#xff1a; 1.新建项目: scrapy startproject weibo_hot 2.新建 spider: scrapy genspider hot_search "weibo.com" 3…...

【网络基础】——传输层

目录 前言 传输层 端口号 端口号范围划分 知名端口号 进程与端口号的关系 netstat UDP协议 UDP协议位置 UDP协议格式 UDP协议特点 面向数据报 UDP缓冲区 UDP的使用注意事项 基于UDP的应用层协议 TCP协议 TCP简介 TCP协议格式 确认应答机制&#…...

删除字符串特定的字符(fF)C语言

代码&#xff1a; #include <stdio.h> void funDel(char *str) {int i, j;for (i j 0; str[i] ! \0; i)if (str[i] ! f && str[i] ! F)str[j] str[i];str[j] \0; }int main() {char str[100];printf("请输入一个字符串&#xff1a;");gets(str);pr…...

C++入门(1):命名空间,IO流 输入输出,缺省参数

一、命名空间 1.1 命名空间的作用&#xff1a; ​ 避免标识符命名冲突 1.2 命名空间定义&#xff1a; 关键字&#xff1a;namespace namespace test {// 命名空间内可以定义变量/函数/类型int a 10;int Add(int x, int y){return x y;}struct Stack{int* a;int top;int …...

【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器

一.自适应梯度算法Adagrad概述 Adagrad&#xff08;Adaptive Gradient Algorithm&#xff09;是一种自适应学习率的优化算法&#xff0c;由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率&#xff0c;适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...

JVM垃圾回收机制全解析

Java虚拟机&#xff08;JVM&#xff09;中的垃圾收集器&#xff08;Garbage Collector&#xff0c;简称GC&#xff09;是用于自动管理内存的机制。它负责识别和清除不再被程序使用的对象&#xff0c;从而释放内存空间&#xff0c;避免内存泄漏和内存溢出等问题。垃圾收集器在Ja…...

oracle与MySQL数据库之间数据同步的技术要点

Oracle与MySQL数据库之间的数据同步是一个涉及多个技术要点的复杂任务。由于Oracle和MySQL的架构差异&#xff0c;它们的数据同步要求既要保持数据的准确性和一致性&#xff0c;又要处理好性能问题。以下是一些主要的技术要点&#xff1a; 数据结构差异 数据类型差异&#xff…...

SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现

摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序&#xff0c;以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务&#xff0c;提供稳定高效的数据处理与业务逻辑支持&#xff1b;利用 uniapp 实现跨平台前…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

深度学习习题2

1.如果增加神经网络的宽度&#xff0c;精确度会增加到一个特定阈值后&#xff0c;便开始降低。造成这一现象的可能原因是什么&#xff1f; A、即使增加卷积核的数量&#xff0c;只有少部分的核会被用作预测 B、当卷积核数量增加时&#xff0c;神经网络的预测能力会降低 C、当卷…...

C++使用 new 来创建动态数组

问题&#xff1a; 不能使用变量定义数组大小 原因&#xff1a; 这是因为数组在内存中是连续存储的&#xff0c;编译器需要在编译阶段就确定数组的大小&#xff0c;以便正确地分配内存空间。如果允许使用变量来定义数组的大小&#xff0c;那么编译器就无法在编译时确定数组的大…...

SQL慢可能是触发了ring buffer

简介 最近在进行 postgresql 性能排查的时候,发现 PG 在某一个时间并行执行的 SQL 变得特别慢。最后通过监控监观察到并行发起得时间 buffers_alloc 就急速上升,且低水位伴随在整个慢 SQL,一直是 buferIO 的等待事件,此时也没有其他会话的争抢。SQL 虽然不是高效 SQL ,但…...

华为OD机考-机房布局

import java.util.*;public class DemoTest5 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseSystem.out.println(solve(in.nextLine()));}}priv…...

腾讯云V3签名

想要接入腾讯云的Api&#xff0c;必然先按其文档计算出所要求的签名。 之前也调用过腾讯云的接口&#xff0c;但总是卡在签名这一步&#xff0c;最后放弃选择SDK&#xff0c;这次终于自己代码实现。 可能腾讯云翻新了接口文档&#xff0c;现在阅读起来&#xff0c;清晰了很多&…...