类之间结构关系_类与结构之间的区别

类之间结构关系

Here you will learn about difference between class and structure.

在这里,您将了解类和结构之间的区别。

A class and a structure, both are user defined data types and understanding the difference between both of them might be confusing at times. In order to understand this, the following table shows clear differences between the two.

一个类和一个结构,都是用户定义的数据类型,理解两者之间的差异有时可能会造成混淆。 为了理解这一点,下表显示了两者之间的明显区别。

ClassStructure
It is a reference data type and uses the keyword “class”.It is a value data type and uses the keyword “struct”.
Object for a class is created in the heap memory.Object for a structure is created in the stack memory.
We can always inherit another class. i.e., the concept of inheritance is applied .Structures can never be inherited.
Object is created using the “new” keyword.We may or may not use the keyword “new” while creating objects.
It occupies more space.A structure occupies less space.
Class allows both the parameterized and the non parameterized constructors.It only allows for the parameterized constructors, even the default constructors cannot be used.
Example:

class fruits

{

Fruit F1;

F1.apple= “red”;

F1.mango=”yellow”;

}

Example:

public struct fruit

{

public string apple;

public string mango;

}

结构体
它是一种参考数据类型,使用关键字“ class”。 它是一个值数据类型,并使用关键字“ struct”。
类的对象在堆存储器中创建。 在堆栈存储器中创建结构的对象。
我们总是可以继承另一个类。 即,继承的概念被应用。 结构永远不能被继承。
使用“ new”关键字创建对象。 创建对象时,我们可能会或可能不会使用关键字“ new”。
它占用更多空间。 结构占用更少的空间。
类允许参数化和非参数化构造函数。 它仅允许使用参数化的构造函数,即使默认构造函数也无法使用。
例:

类水果

{

水果F1;

F1.apple =“红色”;

F1.mango =“黄色”;

}

例:

公共结构的果实

{

公共苹果

公共字符串芒果;

}

翻译自: https://www.thecrazyprogrammer.com/2019/01/difference-between-class-and-structure.html

类之间结构关系

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值