문제

I am trying to get my head around some of my predecessors code who, helpfully, has used 'var' to declare everything.

I have a using statement which is below:

using (var postStream = request.GetRequestStream())
{
    postStream.Write(byteData, 0, byteData.Length);
}

When I put a breakpoint here, postStream shows up in the Autos window as System.Net.ConnectStream. Instead of 'var' I want to use 'ConnectStream' but the compiler doesn't like this.

What am I missing, why can't I write my code like this:

using (ConnectStream postStream = request.GetRequestStream())
{
    postStream.Write(byteData, 0, byteData.Length);
}

I know this is trivial but I was always taught not to use 'var' unless you have a specific reason to do so (such as when dealing with LINQ). Am I wrong?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top