Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Static class

Static class

Scheduled Pinned Locked Moved C#
toolshelpquestion
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LIUCKAS
    wrote on last edited by
    #1

    Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

    A L N W L 5 Replies Last reply
    0
    • L LIUCKAS

      Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

      A Offline
      A Offline
      Andrew Kirillov
      wrote on last edited by
      #2

      Hello You've missed reading MSDN: "The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types." With best regards, Andrew

      1 Reply Last reply
      0
      • L LIUCKAS

        Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        static classes is a new feature in .NET 2.0 (still in beta). Are you sure you're not programming for .NET 1.1? regards

        1 Reply Last reply
        0
        • L LIUCKAS

          Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

          N Offline
          N Offline
          Niklas Ulvinge
          wrote on last edited by
          #4

          A static class can't create an object and thereby it can't have a construcor. The PROgrammer Niklas Ulvinge aka IDK

          R 1 Reply Last reply
          0
          • L LIUCKAS

            Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

            W Offline
            W Offline
            Wraith2
            wrote on last edited by
            #5

            Consider: public abstract sealed class Tools { private Tools(){} } The static modifier in c#2.0 is implemented this way.

            1 Reply Last reply
            0
            • N Niklas Ulvinge

              A static class can't create an object and thereby it can't have a construcor. The PROgrammer Niklas Ulvinge aka IDK

              R Offline
              R Offline
              Robert Rohde
              wrote on last edited by
              #6

              Thats wrong. In .Net static constructors are allowed which are called the first time the class is used:

              public class Blubb() {
              static Blubb() {
              //Do something
              }
              }

              Note that no more modifiers are allowed and that this constructor cannot be called explicitely (the framwork handles this).

              N 1 Reply Last reply
              0
              • R Robert Rohde

                Thats wrong. In .Net static constructors are allowed which are called the first time the class is used:

                public class Blubb() {
                static Blubb() {
                //Do something
                }
                }

                Note that no more modifiers are allowed and that this constructor cannot be called explicitely (the framwork handles this).

                N Offline
                N Offline
                Niklas Ulvinge
                wrote on last edited by
                #7

                OK thanks. I didn't know that. I'll maby use it someday. The PROgrammer Niklas Ulvinge aka IDK

                1 Reply Last reply
                0
                • L LIUCKAS

                  Hi, i have wrote this code to create a static class public static class Tools { public static Tools() {} } but the complier give me this error : The modifier 'static' is not valid for this item. (referring to the class declaration) What i miss? thanks

                  L Offline
                  L Offline
                  LIUCKAS
                  wrote on last edited by
                  #8

                  thank you very much. Actually i'm using .net 1.1, i didn't know that this feature is implemented only in 2.0. I'll try another way...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups