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",我很是不解,这是怎么得来的呀还有就是继承、派生、基类的三者的关系是什么呀,接口又是用来干嘛用的望高手解答,本人新手,越详细越好^-^
Console.WriteLine(myObj.ToString());//myObj 把转成字符串输出。text.MyComplexClass//txt是你的名空间,MyComplexClass是你的类型
tostring方法可重写,重写可以实现你所需要功能.
象楼主的代码,tostring不是十分必要的,任何类型想连结,tostring是自动调用.http://topic.csdn.net/u/20080104/21/b3fc55b3-08f9-4542-9a5d-8ab4fb43211d.html
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.