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. how can i create public variable

how can i create public variable

Scheduled Pinned Locked Moved C#
question
5 Posts 3 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.
  • V Offline
    V Offline
    vipinpaliwal1980
    wrote on last edited by
    #1

    hi all, how can i create a public variable like string vb="ddd"; i just use vb value any class. how can i do this

    sdfsdfsdfs

    S 1 Reply Last reply
    0
    • V vipinpaliwal1980

      hi all, how can i create a public variable like string vb="ddd"; i just use vb value any class. how can i do this

      sdfsdfsdfs

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      C# doesn't permit global variables. The best you can do is create a class with a static member like this

      class YourClass
      {
         public static string vb = "ddd";
      }
      ...
      void YourMethod()
      {
         string f = YourClass.vb;
      }

      Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      R 1 Reply Last reply
      0
      • S S Senthil Kumar

        C# doesn't permit global variables. The best you can do is create a class with a static member like this

        class YourClass
        {
           public static string vb = "ddd";
        }
        ...
        void YourMethod()
        {
           string f = YourClass.vb;
        }

        Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        If I'm not mistaken, YourClass needs to be public? /ravi

        My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        S 1 Reply Last reply
        0
        • R Ravi Bhavnani

          If I'm not mistaken, YourClass needs to be public? /ravi

          My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          The default accessibility for a class is internal, so as long as the class is used within the same assembly, it should work fine. Otherwise, as you said, the class needs to be public.

          Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

          R 1 Reply Last reply
          0
          • S S Senthil Kumar

            The default accessibility for a class is internal, so as long as the class is used within the same assembly, it should work fine. Otherwise, as you said, the class needs to be public.

            Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            Quite right. /ravi

            My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

            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