locked
static class in C# RRS feed

  • Question

  • User-1498642026 posted

    hi 

    static class emp{

      static  string name; // static

             stribg addres; // non static

     

    }

    what is the diff between name ,addres inside the static class

    Tuesday, September 16, 2014 4:08 AM

Answers

  • User753101303 posted

    Hi,

    To me you shouldn't be able to compile this code. If the class is defined as static, you shouldn't be able to declare non static members in it...

    Have you tried to compile this code?

    Edit: from http://msdn.microsoft.com/en-us/library/79b3xss3.aspx :

    "The following list provides the main features of a static class:

    • Contains only static members.

    • etc..."

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2014 4:57 AM
  • User-1925713106 posted

    Hi Siddu,  

    Thanks for your post.

    I tested this code and as PatriceSc said, only static members can be defined in static Class.

        static class emp
        {
            static string name;
            static string address;
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 17, 2014 7:03 AM

All replies

  • User753101303 posted

    Hi,

    To me you shouldn't be able to compile this code. If the class is defined as static, you shouldn't be able to declare non static members in it...

    Have you tried to compile this code?

    Edit: from http://msdn.microsoft.com/en-us/library/79b3xss3.aspx :

    "The following list provides the main features of a static class:

    • Contains only static members.

    • etc..."

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2014 4:57 AM
  • User-1925713106 posted

    Hi Siddu,  

    Thanks for your post.

    I tested this code and as PatriceSc said, only static members can be defined in static Class.

        static class emp
        {
            static string name;
            static string address;
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 17, 2014 7:03 AM