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 to reference a string from another class?

How to reference a string from another class?

Scheduled Pinned Locked Moved C#
tutorialquestion
3 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.
  • C Offline
    C Offline
    ckruger
    wrote on last edited by
    #1

    I'm in one class and would like to use a string that was defined in another class. Ho to...

    V C 2 Replies Last reply
    0
    • C ckruger

      I'm in one class and would like to use a string that was defined in another class. Ho to...

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Is the string a static member or instance member? A static member can be referenced without object references like

      MessageBox.Show(ClassWithString.MyString);

      If it's an instance member, you have to create an instance and then refer to it like

      ClassWithString cws = new ClassWithString();
      MessageBox.Show(cws.MyString);

      Of course, I'm assuming that ClassWithString is accessible from your code and that the string is public. HTH. :) Cheers, Vikram.


      "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

      1 Reply Last reply
      0
      • C ckruger

        I'm in one class and would like to use a string that was defined in another class. Ho to...

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Here is an article on passing values between forms[^] (Remembering that a Form is just another type of class)


        My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius

        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