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. Inheritance problem

Inheritance problem

Scheduled Pinned Locked Moved C#
oophelpquestion
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.
  • S Offline
    S Offline
    sharpone
    wrote on last edited by
    #1

    :confused:Why won't this code work? using System; using System.Windows.Forms; namespace Practice { class Practice { public static void Main() { // declare and assign a string variable called human string human; human = "Walking & talking life"; // declare and assign an int variable called mind int mind; mind = 100; // Print the value of the variables to the console Console.WriteLine(mind); Console.WriteLine(human); } } class Continued { public static void notMain() { MessageBox.Show(human); MessageBox.Show(mind); } } }

    L R 2 Replies Last reply
    0
    • S sharpone

      :confused:Why won't this code work? using System; using System.Windows.Forms; namespace Practice { class Practice { public static void Main() { // declare and assign a string variable called human string human; human = "Walking & talking life"; // declare and assign an int variable called mind int mind; mind = 100; // Print the value of the variables to the console Console.WriteLine(mind); Console.WriteLine(human); } } class Continued { public static void notMain() { MessageBox.Show(human); MessageBox.Show(mind); } } }

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      You did not mention what did not work, but I can guess it is the line: MessageBox.Show(mind); unlike Console.WriteLine, MessageBox.Show does not have an overload that takes an int. Try: MessageBox.Show(mind.ToString()); -------- "I say no to drugs, but they don't listen." - Marilyn Manson

      1 Reply Last reply
      0
      • S sharpone

        :confused:Why won't this code work? using System; using System.Windows.Forms; namespace Practice { class Practice { public static void Main() { // declare and assign a string variable called human string human; human = "Walking & talking life"; // declare and assign an int variable called mind int mind; mind = 100; // Print the value of the variables to the console Console.WriteLine(mind); Console.WriteLine(human); } } class Continued { public static void notMain() { MessageBox.Show(human); MessageBox.Show(mind); } } }

        R Offline
        R Offline
        Ricardo Mendes
        wrote on last edited by
        #3

        The human and mind variables are only visible inside the Main method. To do what you want you need something like this:

        class Practice
        {
        public static string human;
        public static int mind;

        public static void Main()
        {
            human = "Walking & talking life";
            mind = 100;
        }
        

        }

        class Continued
        {
        public static void notMain()
        {
        MessageBox.Show(Practice.human);
        MessageBox.Show(Practice.mind);
        }
        }

        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