C#Get Set [英] C# Get Set

查看:114
本文介绍了C#Get Set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到我认为应该是一个简单的答案。 当涉及到Class的属性并获取和设置属性的值时,哪个属性呢? 语法告诉我,Get实际获取应用程序的值,
然后Set设置属性的值,它将该值提供给类的字段。 例如:


公共类产品


{


私人字符串代码;


public Product(){} //默认构造函数


公共字符串名称


{


   获取 


    {


       返回姓名;


     }



     设置


      {


          name = value;


     }


}



据我了解,实际的C#代码提供了价值,该类别产品的"名称"。 但是该集合是否从应用程序接收到该值,然后get从该集合中获取该值,然后在该类中填充字段
Name?


我知道这可能是一个非常有用的问题,但实际上是从应用程序接收信息? 获取或设置?  Set'设置'是根据应用程序提供的值设置的,还是Get'获取'
应用程序的值和'设置'类中的值?


顺便说一句,我认为我有一些条款和流程不正确,因此非常感谢对术语和流程的任何更正。 我很难(无论我读什么)了解数据如何从应用程序传到课堂。


谢谢!


解决方案

为什么你不能简单地尝试你的代码,你从中学到更多东西,花费的时间少于写这条消息。 


不要认为您可以使用此消息更改它的使用方式,它就像从属性开始以来一样。 


顺便说一下,当你测试它时,要添加一个字符串name ="";


I am struggling to find what I think should be a simple answer.  When it comes to properties of a Class and getting and setting the value of the property, which does which?  Grammar tells me, the Get actually Gets the value from the application, and then the Set sets that value of the property, which provides that value to the field(s) of the class.  For example:

public class Product

{

private string code;

public Product() {} //a default constructor

public string Name

{

    get 

    {

        return name;

     }

     set

     {

         name = value;

     }

}

It is my understanding, the actual C# code is providing the value, the 'name' of the product to the class.  But is the set receiving the value from the application and then in turn the get is getting that value from the set and then populating the field Name in the class?

I know this is probably a very remedial question, but which is actually receiving the information from the application?  The Get or the Set?  Is the Set 'setting' the value based on what is provided from the application or is the Get 'getting' the value from the application and 'setting' that value in the class?

BTW, I assume I have some terms and flow incorrect, so any corrections on terminology and flow are greatly appreciated.  I am having a hard time (no matter what I read) understanding how the data gets from the application to the class.

Thanks!

解决方案

Why do you not simply try your code, you learn much more from it and takes less time than writing this message. 

Don't think that you can change with this message how it is used, it is simply as it is since the beginning of properties. 

By the way, when you test it, than add a string name = "";


这篇关于C#Get Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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