简体   繁体   English

如何在C#中为属性类设置新实例。

[英]How can I set new instance for a property class in C#.

Actually I want to reset the SpintexEditorProperty class. 实际上,我想重置SpintexEditorProperty类。 This contains the static properties. 这包含静态属性。 I want to reset all those properties so that i set new instance but it is not functioning... Please help me... Thanks in advance! 我想重置所有这些属性,以便我设置新实例,但是它不起作用...请帮助我...预先感谢!

//Reset the SpintexEditorPropertyMain //重置SpintexEditorPropertyMain

   internal static void ResetSpintexEditorPropertyMain()
   {
       SpintexEditorPropertyMain = new SpintexEditorProperty();

   }

If class contains static properties then directly access the properties, you don't have to create a new instance to change static properties 如果类包含静态属性,则直接访问属性,则无需创建新实例来更改静态属性

Example SpintexEditorProperty.propertyname = null, this will reset the property 示例SpintexEditorProperty.propertyname = null,这将重置属性

Static properties are not reset when you create a new instance of the class containing those properties. 创建包含这些属性的类的新实例时,不会重置静态属性。 Static fields are meant to remain the same for all the instances of that class. 对于该类的所有实例,静态字段均应保持不变。

if you want to reset their values you will have to do them explicitly. 如果要重置其值,则必须显式地进行设置。 Something like this. 这样的事情。

 public static void ResetStaticProperties()
 {
     SpintexEditorProperty.Property1 = 0;
     SpintexEditorProperty.Property2 = 0;
     SpintexEditorProperty.Property3 = 0;
 } 

and call this method whereever you want to reset them 并在您想重置它们的任何地方调用此方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#。 如何使用基类中描述的方法以及继承的类的参数? - C#. How can I use a method described in a base class with the arguments of inherited class? Selenium C#。 在新的 window 上打开文件后如何下载文件? - Selenium C#. How can I download a file after it is opened on a new window? C#的新手。 你调用的对象是空的。 nJupiter LDAP - New to C#. Object Reference not set to an instance of an object. nJupiter LDAP 如何检查类属性是否在 C# 中设置? - How can I check if a class property is set in C#? 重载operator =在C#中。 我怎么能接受其他类型? - overload operator = in C#. How can i accept other types? 流畅的 NHibernate C#。 我如何从两个不同的程序集中使用表模型(实体)和她的 Map 类? - Fluent NHibernate C#. How I can use table model(entity)and her Map class from two different assemblies? C#。 我可以自动替换派生类而不是基类吗 - C#. Can I automatically substitute derived class instead of base class 如何使用 c# 在运行时创建类的新实例? - How can I create a new instance of a class at run time using c#? C#:如何从派生类设置属性的最大值? (而不是在基类中) - C#: How can I set a maximal Value of a property from a derived class? (And not in base class) 更改属于另一个 C# 类的 XAML 的属性。 (桌面版 WinUI 3) - Change a property that belongs to a XAML of another class C#. (WinUI 3 for Desktops)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM