using System;
 class Pen 
{
public string Color;
private int Price;
public void SetPrice(int newPrice)
     {
    Price=newPrice;
      }
public int GetPrice()
{
return Price;
}
public void SetColor(string newColor)
{
Color=newColor;
}
public string GetColor()
{
return Color;
}
}
class Test
{
public static void Main()
{
Pen myPen;
myPen.SetPrice(5);
myPen.Color="Black";
Console.WriteLine("The Price is {0}".myPen.GetPrice());
        Console.WriteLine("The Color is {0}".myPen.Color);
}
}
出错:"string"并不包含对“mypen"的定义!

解决方案 »

  1.   

    Console.WriteLine("The Price is {0}".myPen.GetPrice());
            Console.WriteLine("The Color is {0}".myPen.Color);.myPen
    应该是
    ,myPen
      

  2.   

    要先实例,既new一下,才可以使用类中的方法
      

  3.   

    回复人: LiJoe(有看贴的权利,没有回帖的义务) ( ) 信誉:100  2005-03-23 16:21:00  得分: 0  
     
     
       Console.WriteLine("The Price is {0}".myPen.GetPrice());
            Console.WriteLine("The Color is {0}".myPen.Color);.myPen
    应该是
    ,myPen
      
     
    Top  
     
     回复人: wolfofsky(风之武) ( ) 信誉:100  2005-03-23 16:25:00  得分: 0  
     
     
       Pen myPen=new Pen();