using System;

namespace Lesson05_2
{
class MainClass
{
public static void Main (string[] args)
{
//初始化Weapon结构体
// Weapon w1;
// Weapon w2 = new Weapon ();//调用当前Weapon结构体的默认构造方法
//验证结构体是否是值类型
// w1.name = "荒古遗尘太刀";
// w1.damage = 1111;
// w1.price = 2222;
//
// w2 = w1;
// w1.name = "荒古遗尘短剑";
// Console.WriteLine (w2.name);

// Vector3 v;
// v.X = 0.0f;
// v.Y = 1.0f;
// v.Z = 2.0f;

// Vector3 v2 = new Vector3 (11.1f, 12.5f, 111.6f);
// Console.WriteLine (v2.X);
// student stu1 = new student( "学生1", 17, 201801, 26 );
// student stu2 = new student( "学生2", 20, 201801, 89 );
// student stu3 = new student ("学生3", 19, 201801, 55);
// student stu4 = new student ("学生4", 18, 201801, 11);
// student[] stu10 = new student[] {
// stu1,
// stu2,
// stu3,
// stu4
// };
// float max = stu10[0].grade;
// string index = stu10 [0].name;
// for (int i = 1; i < stu10.Length; i++) {
// if (max < stu10[i].grade) {
// max = stu10 [i].grade;
// index = stu10 [i].name;
// }
// }
// Console.WriteLine (index);
// for (int i = 0; i < stu10.Length - 1; i++) {
// for (int j = 0; j < stu10.Length - i -1; j++) {
// if (stu10[j].age > stu10[j+1].age) {
// student stu = stu10[j];
// stu10 [j] = stu10 [j + 1];
// stu10 [j + 1] = stu;
// }
// }
// }
// for (int i = 0; i < stu10.Length; i++) {
// stu10 [i].introduce();
// }

}
//访问修饰符public, private, protected ,internal ,protected internal

//定义结构体
// struct Weapon
// {
// //结构体中的字段,属性,方法默认是受保护
// //受保护:以上的结构体成员外界获取不到
// //如果我们想在外界访问结构体成员时,那就需要修改结构体成员的保护
// public string name; //结构体中不能对字段进行初始化
// public float damage;
// public float price;
// }
//
// struct Vector3
// {
// public float X;
// public float Y;
// public float Z;
// //定义初始化结构体成员变量的方法(自定义的结构方法)
public Vector3(float X,float y,float z){
this.X = X; //当前结构体 变量
Y = y;
Z = z;
}
public Vector3(float x){
X = x;
Y = 0;
Z = 0;
}
public Vector3(float x,float y){
X = x;
Y = y;
    Z = 0;
}
// }

struct student
{
public string name;
public int age;
public int student_id;
public float grade;

public student(string n,int a,int i,float g){
name = n;
age = a;
student_id = i;
grade = g;
}

public void introduce(){
Console.WriteLine ("我叫{0},今年{1},我的学号是{2},我考了{3}",name,age,student_id,grade);
}
}

}
}

C#Lesson05_2 结构体相关推荐

  1. Gin 框架学习笔记(02)— 参数自动绑定到结构体

    参数绑定模型可以将请求体自动绑定到结构体中,目前支持绑定的请求类型有 JSON .XML .YAML 和标准表单 form数据 foo=bar&boo=baz 等.换句话说,只要定义好结构体, ...

  2. Go 知识点(04)— 结构体字段转 json格式 tag 标签的作用

    我们知道在 Go 语言中无论是变量.常量还是函数,对于首字母大小写有不同的处理. 首字母大写,标志着该字段或者函数是能导出的,也就是可以被其它包所能访问的: 首字母小写,标志着该字段是私有的,只能在本 ...

  3. 【C#】枚举_结构体_数组

    最近看C#视频,关于这部分,先看了一遍,又照着敲了一遍,自己敲的过程发现了一些有意思的东西. 枚举:定义一个枚举类型的变量,这个变量有很多相同类型的值.比如性别Gender这个变量可以有男和女这两个值 ...

  4. C++ 结构体struct 的使用

    结构体是什么 结构体是一种有开发者定义的数据类型,以容纳许多不同的数据值 结构体的注意事项: 声明结构体的方式和声明类的方式大致相同,其区别如下: 使用关键字 struct 而不是关键字 class. ...

  5. C语言结构体篇 结构体

    在描述一个物体的属性的时候,单一的变量类型是无法完全描述完全的.所以有了灵活的结构体变量. 结构体变量从意义上来讲是不同数据类型的组合,从内存上来讲是在一个空间内进行不同的大小划分. 1.1 结构体类 ...

  6. 33. 使用fread()/fwrite()往文件中写入结构体,从文件中读出结构体

    1 //读写结构体 2 #include <stdio.h> 3 typedef struct student 4 { 5 int num; 6 char name[30]; 7 char ...

  7. Linux 准确查找结构体定义位置

    例如:查找文件操作结构体 struct file_operations, 使用转移符 "\" $ grep struct\ file_operations\ { kernel/in ...

  8. Go 学习笔记(33)— Go 自定义类型 type(自定义结构体、结构体初始化、结构体内嵌、自定义接口)

    1. 自定义类型格式 用户自定义类型使用关键字 type ,其语法格式是: type newType oldType oldType 可以是自定义类型.预声明类型.未命名类型中的任意一种. newTy ...

  9. Go 学习笔记(27)— type 关键字(类型定义、类型别名、类型查询、定义接口、定义结构体)

    1. 类型别名定义 定义类型别名的写法为: type TypeAlias = Type 类型别名规定: TypeAlias 只是 Type 的别名,本质上 TypeAlias 与 Type 是同一个类 ...

最新文章

  1. Nginx 反向代理工作原理简介与配置详解
  2. leetcode中求subset、全排列等问题的回溯算法总结
  3. 【计算机视觉】究竟谁能解决可解释性 AI?
  4. nodejs上传图片并展示
  5. canvas 五子棋游戏
  6. 【SpringMVC】SpringMVC+Spring+hibernate整合
  7. matlab期权风险评估算法,使用 MATLAB 应用程序根据期权价格估算风险中性密度 (risk-neutral density, RND)...
  8. python使用-Python3 错误和异常
  9. 分子动力学模拟AMBER参数意义
  10. 活动喵怎么用?定向寻宝活动设计思路和实操(附2019最新教程)
  11. 百度股市通如何实现智能选股?
  12. redirect_uri参数错误
  13. 美国会委员会建议禁止中国国企收购美国资产
  14. 搞定签到码,一切皆可码!!!微信小程序篇
  15. Cosine Similarity 与 L2distanse
  16. APP服务器需要什么样的配置
  17. LiteFlowNet3:解决对应歧义以获得更准确的光流估计
  18. 取消华为mate30 删除图片时手机弹出提示:“..检测xx删除了图片..“
  19. Workbench螺栓连接的模拟方法
  20. npm WARN webpack-cli@3.3.11 requires a peer of webpack@4.x.x but none is installed. You must install

热门文章

  1. JSP密码不少于6位
  2. Klocwork — 符合功能安全要求的自动化静态测试工具
  3. [sensor]如何解决光感不灵敏的问题
  4. 抖音店铺商品详情API,订单交易详情接口
  5. 软件测试能干多长时间
  6. 时间复杂度和空间复杂度分析技巧
  7. 传李国宝与美国监管当局就道琼斯案和解
  8. 如何判断数组被填满?
  9. eaysui中treegrid无法显示父节点
  10. Docker安装Portainer