using System;
namespace test
{
public abstract class MyBase
{     //指定类可在任务地方访问,不能实例化,只能继承
}
internal class MyClass : MyBase
{    //指定基类MyBase
}
public interface IMyBaseInterface
{ //接口
}
internal interface IMyBaseInterface2
{    //接口
}
internal interface IMyYnterface : IMyBaseInterface,IMyBaseInterface2
{    //给接口指定基类IMyBaseInterface,
}
internal sealed class MyComplexClass : MyClass,IMyBaseInterface
{     //指定为密封类
}
class test
{
static void Main(string[] args)
{
MyComplexClass myObj = new MyComplexClass();
Console.WriteLine(myObj.ToString());
Console.ReadKey();
}
}
}程序的返回结果是"text.MyComplexClass",我很是不解,这是怎么得来的呀还有就是继承、派生、基类的三者的关系是什么呀,接口又是用来干嘛用的望高手解答,本人新手,越详细越好^-^

解决方案 »

  1.   

    当然是text.MyComplexClass了。MyComplexClass myObj = new MyComplexClass();//实例化一个MyComplexClass类型的对象
    Console.WriteLine(myObj.ToString());//myObj 把转成字符串输出。text.MyComplexClass//txt是你的名空间,MyComplexClass是你的类型
      

  2.   

    还是没太明白, test.MyComplexClass 这个值是怎么得来的,有什么根据没有呀
      

  3.   

    tostring一般是将对象转换成string型,在.net中,任何对象都有tostring方法,因为任何对象都是从object继承而来,而object就是有tostring 这个方法,一般对是数值类型,tostring就是将数值类型转换成string类型,对于一些引用类型,如dataset等,一般tostring是返回以象的类型名. 
    tostring方法可重写,重写可以实现你所需要功能. 
    象楼主的代码,tostring不是十分必要的,任何类型想连结,tostring是自动调用.http://topic.csdn.net/u/20080104/21/b3fc55b3-08f9-4542-9a5d-8ab4fb43211d.html
      

  4.   

    1.并不是所有类都有ToString方法,因为有些子类并未继承或者实现OBJECT父类的该方法.
    2.Object..::.ToString Method 
    这个是MSDN的标准解释:
    This method returns a human-readable string that is culture-sensitive. For example, for an instance of the Double class whose value is zero, the implementation of Double..::.ToString might return "0.00" or "0,00" depending on the current UI culture.The default implementation returns the fully qualified name of the type of the Object.