如何在c#中更改属性名称? [英] How to change Property name in c#?

查看:109
本文介绍了如何在c#中更改属性名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的Model类中有两个属性。我正在使用MVC 4.例如我有以下课程及其所属财产 -

Hi,

I have two property in my Model class. I am using MVC 4. For example i am having below class and its belonging property -

Public Class Test

{

public string Custom1 {get;set;}

public string Custom2 {get;set;}

}



当我绑定这个Test模型类时,它正常工作。我想要的,我想保留属性名称Custom1和Custom2,但想要更改其名称。



意味着,Custom1将在那里,但我访问此属性与不同名称如EmailId和密码而不是Custom1和Custom2。



请在此建议。



谢谢。


When i am binding this Test model class, it working properly. What i want, i want to keep property name Custom1 and Custom2 but want to change its name.

Means, Custom1 will be there but i am accessing this property with different name like EmailId and Password instead of Custom1 and Custom2.

Please suggest on this.

Thanks.

推荐答案

你好,

你不能这样做。要更改属性名称,您可以在类中更改它,或者您可以从此类创建子类,并更改派生类中某个属性的名称。
Hello ,
You can not do this . To change the property name you may change it in class or you can make a sub class from this class, and change the name of certain property in the derived class.


您可以做的是这个:

你创建一个继承Test类的新类Test2。

在这个类中你可以添加一个属性EmailID,它使用来自的值来自基类的Custom1。在这种情况下,您必须编程getter-和setter-methods完全能够使用新属性EMailID传递(例如)Custom1的值。
What you can do is this :
You create a new class "Test2" which inherits the class "Test".
In this class you can add a Property "EmailID" which uses the value from "Custom1" from the base-class. In this case you have to programm the getter- and the setter-methods completly out to be able to deliver the value of (for example) "Custom1" with the new Property "EMailID".


这篇关于如何在c#中更改属性名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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