简体   繁体   中英

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

Actually I want to reset the SpintexEditorProperty class. 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

   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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM