Home > DeveloperSection > Forums > Is Possible to create property of static class?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    January-13-2016 10:27 PM

 C# C#  .NET 
Ratings:


 1 Reply(s)
 226  View(s)
Rate this:
Hello
I have a static class :

       public static class Demo
        {
            public const string Complete = "Complete";
            public const string Active = "Active";
            public const string Current = "Current";
        }

 

and I want to have a property that will present an occurrence of this static class in another class DemoImplement.

 

    public class DemoImplement
        {
            public string Code { get; set; }
            public string Title { get; set; }
            public string  Status { get; set; }
            public string Category { get; set; }
        }

Thanks in advance.     


Anupam Mishra

Total Post:135

Points:949
Posted on    January-13-2016 10:33 PM

 Hi Manoj,
it's not possible; you do not instantiate a static class.
You can do this:

 public class DemoImplement
{
    public string Code { get; set; }
    public string Title { get; set; }
    public string  Status { get; set; }
    public string Category { get; set; }
    public string MyActive = Demo.Active;
}
void Main()
{
   DemoImplement  DI= new DemoImplement();
    Console.WriteLine (DI.MyActive);
}

output:
Active

Don't want to miss updates? Please click the below button!

Follow MindStick