当前位置: 首页 > 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 …...

Go 语言面试题(三):并发编程

文章目录 Q1 无缓冲的 channel 和 有缓冲的 channel 的区别&#xff1f;Q2 什么是协程泄露(Goroutine Leak)&#xff1f;Q3 Go 可以限制运行时操作系统线程的数量吗&#xff1f; Q1 无缓冲的 channel 和 有缓冲的 channel 的区别&#xff1f; 对于无缓冲的 channel&#xff0c…...

Linux - make命令 和 makefile

make命令和 makefile 如果之前用过 vim 的话&#xff0c;应该会对 vim 又爱又恨吧&#xff0c;刚开始使用感觉非常的别扭&#xff0c;因为这种编写代码的方式&#xff0c;和在 windows 当中用图形化界面的方式编写代码的方式差别是不是很大。当你把vim 用熟悉的之后&#xff0…...

FPGA复习(功耗)

减小功耗 就得减小电流 电流和CF有关&#xff08; C: 电容&#xff08;被门数目和布线长度影响&#xff09; F:时钟频率&#xff09; 方法大纲 减小功耗&#xff1a;1 时钟控制 2输入控制 3减小供电电压 4双沿触发器 5修改终端 同步数字电路降低动态功耗&#xff1a;动态禁止…...

element ui el-table表格复选框,弹框关闭取消打勾选择

//弹框表格复选框清空 this.$nextTick(()>{this.$refs.table.clearSelection();})<el-table ref"table" v-loading"crud.loading" :header-cell-style"{ color: #FFF, background: #333 }":cell-style"{ color: #FFF, background: #3…...

数据结构——队列

1.队列元素逆置 【问题描述】 已知Q是一个非空队列&#xff0c;S是一个空栈。仅使用少量工作变量以及对队列和栈的基本操作&#xff0c;编写一个算法&#xff0c;将队列Q中的所有元素逆置。 【输入形式】 输入的第一行为队列元素个数&#xff0c;第二行为队列从首至尾的元素…...

【Unity引擎核心-Object,序列化,资产管理,内存管理】

文章目录 整体介绍Native & Managed Objects什么是序列化序列化用来做什么Editor和运行时序列化的区别脚本序列化针对序列化的使用建议 Unity资产管理导入Asset Process为何要做引擎资源文件导入Main-Assets和 Sub-Assets资产的导入管线Hook&#xff0c;AssetPostprocessor…...

Generics/泛型, ViewBuilder/视图构造器 的使用

1. Generics 泛型的定义及使用 1.1 创建使用泛型的实例 GenericsBootcamp.swift import SwiftUIstruct StringModel {let info: String?func removeInfo() -> StringModel{StringModel(info: nil)} }struct BoolModel {let info: Bool?func removeInfo() -> BoolModel…...

数据结构之手撕顺序表(增删查改等)

0.引言 在本章之后&#xff0c;就要求大家对于指针、结构体、动态开辟等相关的知识要熟练的掌握&#xff0c;如果有小伙伴对上面相关的知识还不是很清晰&#xff0c;要先弄明白再过来接着学习哦&#xff01; 那进入正题&#xff0c;在讲解顺序表之前&#xff0c;我们先来介绍…...

进阶JAVA篇- ZoneId 类与 ZoneDateTime 类、Instant类的常用API(七)

目录 API 1.0 ZoneId 类的说明 1.1 如何创建 ZoneId 类的对象呢&#xff1f; 1.2 ZoneId 类中的 getAvailableZoneIds() 静态方法 2.0 ZoneDateTime 类的说明 2.1 如何创建 ZoneDateTime 类的对象呢&#xff1f; 3.0 Instant 类的说明 3.1 如何创建 Instant 类的对象呢…...

bat脚本字符串替换:路径中\需要替换,解决一些文件写入路径不对的问题

脚本 set dir_tmp%~dp0 set dir%dir_tmp:\\\\\% set dir_tmp%~dp0 新建一个变量dir_tmp&#xff0c;存储获取的脚本当前路径 set dir%dir_tmp:\\\\\% 新建一个变量dir &#xff0c;存储字符串替换之后的路径 其中黄色的\\实际上代表的是一个\...