c# 中关于: base()用法,在此记录一下,方便查阅
1.this是标识当前资源对象的,而base是基于父级的。
2.base发挥了期灵魂级的作用——多态
3.base子类可以访问父类成员
4.base调用父类方法必须重写父类方法
5.base子类构造函数直接访问:base父类构造方法
6.base同样不能用于静态方法
public abstract class HttpBasedTransport : ClientTransportBase { protected HttpBasedTransport(IHttpClient httpClient, string transportName) : base(httpClient, transportName) { } }
父类
public abstract class ClientTransportBase : IClientTransport { private readonly IHttpClient _httpClient; private readonly string _transportName; private readonly TransportHelper _transportHelper; private readonly TransportAbortHandler _abortHandler; private bool _finished = false; private TransportInitializationHandler _initializationHandler; [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Disposed in the Dispose method.")] protected ClientTransportBase(IHttpClient httpClient, string transportName) : this(httpClient, transportName, new TransportHelper(), new TransportAbortHandler(httpClient, transportName)) { } internal ClientTransportBase(IHttpClient httpClient, string transportName, TransportHelper transportHelper, TransportAbortHandler abortHandler) { if (httpClient == null) { throw new ArgumentNullException("httpClient"); } if (string.IsNullOrWhiteSpace(transportName)) { throw new ArgumentNullException("transportName"); } Debug.Assert(transportHelper != null, "transportHelper is null"); Debug.Assert(abortHandler != null, "abortHandler is null"); _httpClient = httpClient; _transportName = transportName; _transportHelper = transportHelper; _abortHandler = abortHandler; } }
时间: 2024-10-10 09:52:40