????? ????? ?????? ????????? ?? "Visual C" #

?????? ????????? ?????? ?????????
???? ???????: 307368 - ??? ???????? ???? ????? ????? ??? ???????.
?????? ??? ????? Microsoft Visual Basic .NET ?? ??? ???????? ???? 307210.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ????? ????? ??? ????? ?? C# ?????? ???? baseball. ??? ???? ?????? ???? ?????? ?????? ?????. ?? ??? ????? ???? ?? ??? ????? ????? ??? ?????? ??????? ?????? ??????.

C# ??? ????? ?????. ????? ?????? ?????? ??????? ?? ??????? ????? ?? ?? ?? ?????? ?????? ??? ?????? ??? ??????. ???? ?? ????? ??? ??? ???? ?????? ?????? ???????.

???????

????? ??????? ????????:
  • ???? ???? C#
  • ?????? ?????

????? ????? ???? ???? ????

  1. ??? ????? Visual Studio .NET ?? Visual Studio 2005 ?????? C# ???? ????? ????? ???? ???? ClassesAndObjects.
  2. ??? ???????.

????? ??? ?????

  1. ?? ??????? ??????? ???? ??? ????? ???.
  2. ?? ???? ?????? ????? ???? ???? ?????? ??? ??? ??? ???? BaseballTeam ??? ?? ???? ??? ???.

    ?????? ?? Visual C# 2005 ??? ????? ??? ?????.
  3. ??? ????? ????? ??????? ?? ???? "??? ???".

????? ???? ? ?????????

  1. ?? ??????? ???? ???? ??? ??? ?????. ?? ?????? "??? ???" ? ?? ?????? ??????? ClassesAndObjects ?? ?? ?????? ????? ????? ClassesAndObjects. ???? ??? ?????? ?????? ??? ??? BaseballTeam ????? ????? ?? ???? ??? ????? ???.

    ?????? ????? Visual C# 2005 ??? ??????? ???????. ????? ?? ?????????? ?? ?????? ???? Microsoft ?????? ??? ?????:
    http://msdn2.microsoft.com/en-us/library/t27ahy37.aspx
  2. ?? ????? ??? C# ? ????? ??? ?????? ??? ??? ?? ?? ?????? ??? ????? ??? ?????. ??? ????? ? ???? ???. ???? ??? ?????. ???? ??? ??? ????? ??? ??????? ??? ?????:
    private string name;
  3. ??? ???????? 1 ? 2 (?? ????? ????????? ???????? ??????) ? ????? ??? ??? ??? ???:
    private string stadium;
  4. ????? ?????? ?? ????? ?????? ??? ?????? ?????? ??? ???:
    private int wins = 0;
    private int defeats = 0;
  5. ????? ??????? ????? ????? ??? ?????? ?? stadium:
    public BaseballTeam(string n, string s)
    {
       this.name = n;
       this.stadium = s;
    
    }

????? ??????

  1. ?? ??? ???, ???? ??? ?????? ?????? ??? ??? BaseballTeam. ???? ????? ?? ???? ??? ????? ?????.

    ?????? ????? Visual C# 2005 ??? ??????? ???????. ????? ?? ?????????? ?? ?????? ???? Microsoft ?????? ??? ?????:
    http://msdn2.microsoft.com/en-us/library/t27ahy37.aspx
  2. ????? ????? ?????? ??? ???????? ?????? ????? ??? ??? ???? ?????. ??? ??????? ???? PlayGame. ????? ??????? Int ?????? runsFor ? runsAgainst. ???? ??? ?????. ???? ??? ??? ????? ??????? ??????? ??? ?????:
    public void PlayGame(int runsFor, int runsAgainst)
    {
    
    }
  3. ????? ?? ??????? ??? ???:
    public void PlayGame(int runsFor, int runsAgainst)
    {
       if (runsFor > runsAgainst)
          this.wins++;
       else
          this.defeats++;
    
    }
  4. ??? ???? ???? ?? C# ??????? ??? ??? ?????? ???? ????. ????? ??? ????? ????? ??????? ???? ????. ???? ?? ??????? ToString ????? ????? ????? ????? ???. ????? ??? ??????? ?? ????? ??????? BaseballTeam ??? ???:
    public override string ToString()
    {
       return this.name + ", play at " + this.stadium + ": " +
              " W" + this.wins + " L" + this.defeats;
    
    }

????? ?????? overloaded

C# ????? ?????? overloaded ?? ???????? ???? ??? ??? ????? ???? ????? ?????. ?? ?????? 2 ????? ???? ????? ????? overloaded ????? PlayGame ???? ???? ????? ?????? ?????? ????? ??.
  1. ?????? ????? ??????? ?? ??? BaseballTeam ??? ???:
    public enum Result {Win, Lose}
  2. ????? ????? PlayGame ??? ???????:
    public void PlayGame(Result r)
    {
       if (r == Result.Win)
          this.wins++;
       else if (r == Result.Lose)
          this.defeats++;
    
    }

????? ???????

  1. ?? ??? ???, ???? ??? ?????? ?????? ??? ??? BaseballTeam. ???? ????? ?? ???? ??? ????? ?????.

    ?????? ????? Visual C# 2005 ??? ??????? ???????. ????? ?? ?????????? ?? ?????? ???? Microsoft ?????? ??? ?????:
    http://msdn2.microsoft.com/en-us/library/t27ahy37.aspx
  2. ????? ???? ?????? ??? ???????? ?????? ????? ??? ??? ??????. ??? ????? ???? ???. ???? ??? ?? ???? ?????? ??? ?? ???? ??? ?????. ???? ??? ??? ????? ??????? ??????? ??? ?????:
    public double Record
    {
       get
       {
          return 0;
       }
    
    }
  3. ????? ??????? ??? ??? ???? ???? ?????? ????? ?????? baseball ????? ????? (??? ???? ??????? ??? ?????? ??? ??????? 10 ???? ??????? 10 ????? ????? ?? ?? 0.5):
    public double Record
    {
       get
       {
          int played = this.wins + this.defeats;
          return (double)this.wins / played;
       }
    
    }
  4. ????? ????? get/????? ??????? Ballpark ??? ???. ???? ??? ??????? ????? stadium ?????? baseball ?????? ?? ?????:
    public string Ballpark
    {
       get 
       {
          return this.stadium; 
       }
       set 
       {
          this.stadium = value;  // value is an implicit parameter
       }
    
    }

????? ???? ??????????

  1. ??? ????????? ???????? Class1.cs ?? ???? "??? ???".
  2. ?? ??????? ??????? ?????? ???? BaseballTeam ???????? ???? ????? ????. ????? ???? ?????? ??? ????? BaseballTeam ???? ??? ???:
    BaseballTeam sf = new BaseballTeam("San Francisco Giants", 
                                       "Candlestick Park");
  3. ?? ?????? ????????? ???????? ??????? ??????? ?????? ?????? ??? ??????:
    sf.PlayGame(7, 2);
    sf.PlayGame(BaseballTeam.Result.Lose);
  4. ?? ?????? ???????? ??????? ??????? ????? ??????:
    Console.Out.WriteLine("Record: " + sf.Record);
    sf.Ballpark = "3Com Park";
  5. ??? ?????? ??????? ?????? ? ??? ???:
    Console.Out.WriteLine(sf.ToString());
  6. ????? ???? ?????? ??? ???? ????? ?? ??? ????? ?????? BaseballTeam ???????. ???? ??? ?????? ???????? ??????? (???? ?? C# ?? ????? ???? ????? ???):
    sf = null;

???? ?? ??? ????

  1. ?????? ??????? ???????.
  2. ???? ?? ?? ??????? ??? ????????? ??????? ??? ???? ??????:
    Record: 0.5
    San Francisco Giants, play at 3Com Park:  W1 L1

???????

???? ???????: 307368 - ????? ??? ??????: 20/?? ??????/1427 - ??????: 3.3
????? ???
  • Microsoft Visual C# 2005
  • Microsoft Visual C# .NET 2002 Standard Edition
????? ??????: 
kbmt kbhowtomaster KB307368 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????307368

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com