本文介绍了为什么在C#Bean文件中使用私有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,
在C#项目的Bean文件中,我们定义set和get方法.
但是在定义此名称之前,我们先将名称声明为私有字符串.为什么还要将名称声明为私有?是出于安全原因还是其他原因?

Hello Sir,
In the Bean File of C# project we define the set and get methods.
But before define this we declare names as a private string.. So why we declare the name as private? Is this for security reason or any other?

推荐答案



[ ^ ]

属性是一种成员,它提供了一种灵活的机制来读取,写入或计算私有字段的值.可以将属性当作公共数据成员使用,但实际上它们是称为访问器的特殊方法.这样可以轻松访问数据,并且仍然有助于提高方法的安全性和灵活性.

A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.


因此,如果私有变量不是私有变量,则其他类可以获取/设置该变量的值.然后,私有变量将跳过该属性的获取/设置过程.


So, if the private variable isn''t private, then other classes can get/set the value of that variable. And then the private variable skips the get/set process from the property.


这篇关于为什么在C#Bean文件中使用私有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:45
查看更多