Is Possible to create property of static class?

Total Post:154

Points:1086
C#  .NET 
C#
 833  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. 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

      Modified On Apr-11-2018 12:15:37 AM

Answer