IS POSSIBLE TO CREATE PROPERTY OF STATIC CLASS?

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
C#  .NET 
C#
 471  View(s)
Ratings:
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.     
  1. Anupam Mishra

    Post:135

    Points:949
    Re: Is Possible to create property of static class?

     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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!