2014-01-17 4 views
-3

내 질문은 IEnumberable 인터페이스가 그렇다면 왜 .Net은 IEnumerable 인스턴스를 인스턴스화 할 수 있습니까?인터페이스 인스턴스

IEnumerable <string> Errors= new IEnumerable<string>() 

왜 우리 인터페이스를 인스턴스화하지 않습니까?

+0

경우 .NET 인터페이스의 인스턴스 않습니다 수행하려고 할 때이 오류가 발생 하는가? 인터페이스를 구현하는 객체를 해당 인터페이스로 노출하는 것이 아니라고 확신합니까? –

+0

'오류 : 추상 클래스 또는 인터페이스 'System.Collections.Generic.IEnumerable '의 인스턴스를 만들 수 없습니다.'실제로 컴파일되는 코드의 예를 들어 주시겠습니까? –

답변

2

인터페이스의 인스턴스를 만들 수 없다면 주어진 코드가 오류를 던질 것입니다.

Cannot create an instance of the abstract class or interface 'System.Collections.Generic.IEnumerable'

예 클래스와 인터페이스 변수를 초기화 할 수 있습니다 그것을 구현하는 : 당신이

IEnumerable <string> Errors = new List<string>(); 
0

Why .Net allow to instantiate IEnumerable instance

잘 할 수 있습니까?

IEnumerable <string> Errors= new IEnumerable<string>() 

당신이

Cannot create an instance of the abstract class or interface 'System.Collections.Generic.IEnumerable'