Ok So I have two classes that share the same instance variables, the variables have been declared in 'Dog', however I cannot seem to get the instances to work within my other class 'DogChorus'. Therefore what must I do to get the instances to work within 'DogChorus' constructors?

The variables are:

barkSound
breed
dogHeight
dogColour

Code below that I have used:

DOG

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloDogs
{
    class Dog
    {
        private string barkSound;
        private string breed;
        private int dogHeight;
        private string dogColour;
        private static int noOfLEgs;

        public string Breed
        {
            get { return breed; }
            set { breed = value; }
        }
        private string dogSpeech;

        public Dog()
        {
            barkSound = "Woof!";
            breed = "cocker spaniel";
            dogHeight = 10;
            dogColour = "white";

        }

        public string GetSpeech(int passed_size)
        {
            if (IsBig(passed_size) == true)
            {
                dogSpeech = "Hello. I am a " + breed + ". " + barkSound + " I am Big ";
            }
            else
            {
                dogSpeech = "Hello. I am a " + breed + ". " + barkSound + " I am small ";
            }
            return dogSpeech;
        }

        private void SetSound(String barkSound)
        {
        this.barkSound = barkSound;
}
        private static bool IsBig(int size)
        {
        {
        bool Size1;
        if (size < 50)
        {
        Size1 = false;
        }
        else
        {
        Size1 = true;
        return Size1;}}}}

DogChorus

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloDogs
{
    class DogChorus
    {      
        public DogChorus() {
        }
        DogChorus(int a) : this(a, "defaultStringValue")
  {

      barkSound = "Woof!";
      breed = "cocker spaniel";
      dogHeight = 10;
      dogColour = "white";

  }
        DogChorus(int a, string b) 
  {

  } 
        public string GetOutput(){
            return lady.GetSpeech() + " \n " + tramp.GetSpeech();
        }     
}

In the DogChorus constructor you are initializing a bunch of members with the same names as the Dog class (which are all private except for Breed) that aren't actually members of the DogChorus class. Perhaps you mean to have 2 objects of type Dog in this class called lady and tramp? If that is the case, you will need to have some public properties/methods/members/constructor in the Dog class to set the appropriate member variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.