如何从我在c#

时间:2016-10-09 09:47:17

标签: c#

namespace HelloDogs

{     班狗     {         私人字符串barkSound;         私人品种; //将dogHeight,dogColor和noOfLegs添加到
        私人int dogHeight; //私有变量         私人字符串dogColor;        private static int noOfLegs;

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

     public static int NoOfLegs
     {
     get{return noOfLegs; }      // I created properties to encapsulate the variables
        set {noOfLegs = value; }   // dogHeight, dogColor and noOfLegs using the properties
    }

    public int DogHeight
    {
        get {return dogHeight;}
        set{dogHeight = value;}
    }

    public string DogColor
    {
        get {return dogColor;}
        set{ dogColor = value;}
    }

    private string dogSpeech;

    public Dog()
    {
        barkSound = "Jack!";
        breed = "cocker spaniel";
    }
    // Added a new constructor below that takes the  following parameters
    public Dog(int h,string b, string c )
    {

        dogHeight = h;
        dogColor = c;
        breed = b;
    }
    // A private method to check the dogHeight if true or false 
    private bool IsBig(int x)
     {
        if (x < 50)
            return false;
        else
            return true;
    }

//更改下面的GetSpeech方法以显示有关狗的所有详细信息         public string GetSpeech()
        {

        dogSpeech = "Hello, I am a " + breed + " , " + dogHeight  +  "cm"  +  "," 
            + dogColor +  "."  + barkSound ;
        return dogSpeech;

        if(IsBig(dogHeight))
        {
            return dogSpeech = "You are big ";
        } else
        {
            dogSpeech = " You are not big enough";
        }
    }
    public void SetSound(String barkSound)
    {
        this.barkSound = barkSound;

    }


}

}

1 个答案:

答案 0 :(得分:0)

从类中调用static请在msdn中看到 https://msdn.microsoft.com/en-us/library/79b3xss3.aspx