什么是价值类的,什么是在C#中引用类? [英] What is a Value Class and what is a reference Class in C#?

查看:153
本文介绍了什么是价值类的,什么是在C#中引用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中的值类引用类

的定义是什么

这是如何从值类型不同引用类型

我问这个问题,因为我读这在MCTS自学培训工具包(考试70-536)。第1章,第1课,课程回顾4:

  

您需要创建一个简单的类或   结构只包含价值   类型。您必须创建的类或   结构,使得它作为运行   尽可能有效。你一定是   能够在类或结构传递到   而不用担心一个过程,该   过程将修改它。哪   下面应该创建?

     

一个引用类

     

1B参考架构

     

的c值类

     

D值结构

     

正确答案:D

     

有一个不正确:您可以创建一个   引用类;然而,也可能是   修改,可在传递给过程。

     

乙:不正确:不能创建一个   参考结构。

     

ç不正确:您可以创建一个价值   类;然而,结构往往是   更有效。

     

ð正确:值结构   通常是最有效的。

解决方案

值类型是按值传递,而引用类型按引用传递。

编辑:值/引用类
有一个值类或引用类在C#中的概念,所以要求它的定义是没有实际意义。

What is the definition of a value class and reference class in C#?

How does this differ from a value type and reference type?

I ask this question because I read this in the MCTS Self-Paced Training Kit (Exam 70-536). Chapter 1, Lesson 1, Lesson review 4 :

You need to create a simple class or structure that contains only value types. You must create the class or structure so that it runs as efficiently as possible. You must be able to pass the class or structure to a procedure without concern that the procedure will modify it. Which of the following should you create?

A reference class

B reference structure

C value class

D value structure

Correct Answer: D

A Incorrect: You could create a reference class; however, it could be modified when passed to a procedure.

B Incorrect: You cannot create a reference structure.

C Incorrect: You could create a value class; however, structures tend to be more efficient.

D Correct: Value structures are typically the most efficient.

解决方案

Value types are passed by value, while reference types are passed by reference.

Edit: value/reference classes
There is no concept of a 'value class' or 'reference class' in C#, so asking for its definition is moot.

这篇关于什么是价值类的,什么是在C#中引用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆