关于c#结构体(struct)定义详解
来源:互联网 发布:单片机最小系统的作用 编辑:程序博客网 时间:2024/05/16 00:58
C#结构体定义的情况:
C#结构体定义也可以象类一样可以单独定义。
1
2
class
a { };
struct
a { };
1
2
public
struct
student { };
internal
struct
student { };
如果结构体student的元素没有public的声明,对象obj就无法调用元素x,因为默认的结构体名和元素名是private类型。
C#结构体定义之程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using
System;
public
struct
student
{
public
int
x;
}
class
program {
public
static
void
Main()
{
student obj =
new
student();
obj.x = 100;
}
};
C#结构体定义程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using
System;
public
struct
Student
{
public
static
int
A = 10;
}
class
Exe
{
public
static
void
Main()
{
Console.WriteLine(Student.A = 100);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using
System;
class
Base
{
public
struct
Student
{
public
static
int
A = 10;
}
}
class
Exe
{
public
static
void
Main()
{
Console.WriteLine(Base.Student.A = 100);
}
}
C#结构体定义程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
public
struct
Student
{
public
int
x;
public
int
y;
public
static
int
z;
public
Student(
int
a,
int
b,
int
c)
{
x = a;
y = b;
Student.z = c;
}
}
C#结构体定义程序:
1
2
3
4
5
6
7
public
struct
Student
{
public
void
list()
{
Console.WriteLine(
"这是构造的函数"
);
}
}
C#结构体定义程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public
struct
Student
{
public
int
x;
public
int
y;
public
static
int
z;
public
Student(
int
a,
int
b,
int
c)
{
x = a;
y = b;
Student.z = c;
}
}
class
Program
{
public
static
void
Main()
{
Student obj =
new
Student(100, 200, 300);
Student obj2;
obj2.x = 100;
obj2.y = 200;
Student.z = 300;
}
}
C#结构体定义程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using
System;
class
Class_Test
{
public
int
x;
}
struct
Struct_Test
{
public
int
x;
}
class
Program
{
public
static
void
class_t(Class_Test obj)
{
obj.x = 90;
}
public
static
void
struct_t(Struct_Test obj)
{
obj.x = 90;
}
public
static
void
Main()
{
Class_Test obj_1 =
new
Class_Test();
Struct_Test obj_2 =
new
Struct_Test();
obj_1.x = 100; obj_2.x = 100;
class_t(obj_1); struct_t(obj_2);
Console.WriteLine(
"Class_Test obj_1.x={0}"
, obj_1.x);
Console.WriteLine(
"Struct_Test obj_2.x={0}"
, obj_2.x);
Console.Read();
}
}
1
Class_Test obj_1.x=90 Struct_Test obj_2.x=100
C#结构体定义的基本内容就向你介绍到这里,希望对你了解C#结构体定义有所帮助。
- 关于c#结构体(struct)定义详解
- 结构体定义 typedef struct 用法详解
- 结构体定义 typedef struct 用法详解
- 结构体定义 typedef struct 用法详解
- 结构体定义typedef struct详解
- 结构体struct 名称定义详解
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 结构体定义 typedef struct 用法详解和用法小结
- 一本书,让我走上编程之路
- QT中QWidget类简介
- CRect 详解及注意事项
- 指针类型的强制转化及实例分析
- Hunter的读《高效程序员的45个习惯》
- 关于c#结构体(struct)定义详解
- 跨域请求
- Android 开机震动在哪调用的,怎样关闭?
- 黑马程序员————IO流3(day20)
- Android----adb工具的安装
- maven联通网络下中央仓库不能访问的解决办法
- Oracle中的restricted, quiesce, suspend
- 题目1046:求最大值
- 工业相机SDK之opencv二次开发