关于C#中的属性 [英] About Properties in c#

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

问题描述

为什么要在c#中使用属性?给出实时示例的答案?

Why we use properties in c#?Give answer with real time example?

推荐答案

请参阅此链接
http://www.dotnetperls.com/property [
see this link
http://www.dotnetperls.com/property[^]


您是否了解 MSDN:使用属性(C#编程指南) [ ^ ]
MSDN:财产使用准则 [ C#属性 [ ^ ]
C#Station教程:属性 [使用属性的优势 [
Do you know about google[^]? It is giving about 18,900,000 results in 0.32 seconds for your question. Don''t be so lazy.

Refer the links below:
MSDN : Using Properties (C# Programming Guide)[^]
MSDN : Property Usage Guidelines[^]
C# Property[^]
The C# Station Tutorial : Properties[^]
Advantage of using Properties[^]


--Amit


我认为您知道这些详细信息
封装:隐藏细节
抽象:显示必需的信息

如果您了解这些概念,就很容易理解财产.
我会给你一个简单的例子.
您在类strProduct中有一个私有变量.您不想授予访问权限或有关它的任何信息(封装).但是使用您的类的其他类需要处理该变量.因此,您可以通过属性公开该变量.(抽象)

希望对您有所帮助.
I think you are knowing these details
Encapsulation: Hiding details
Abstraction: Show Required information

If you understand these concept it is easy for you to understand property.
I will give you simple example.
You have private variable in your class strProduct.Yo dont want to give access or any info about it(Encapsulation). But other class which is using your class need to handle that variable. So you expose that variable through property.(Abstraction)

Hope it is helpful.


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

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