.
?
, : " -, ".
"-" - - .
, - , , ( - ..). . .
. -, - , .
:
using System.Collections.Generic;
namespace App
{
class Program
{
class Example
{
List<string> list = new List<string> { "a", "b", "c" };
public IEnumerable<string> AsEnumerable()
{
return list;
}
}
static void Main(string[] args)
{
IEnumerable<string> foo = new Example().AsEnumerable();
List<string> bar = (List<string>)foo;
}
}
}
, ?
IEnumerable<string> :
IEnumerable<string> foo = new Example().AsEnumerable();
: "foo - , IEnumerable".
-. IEnumerable , . IEnumerable - , .
List<string>, ? ( #, , Add Remove , . ).
: IEnumerable<string> , .
EDIT:
@Kjartan, :
bool isFooIEnumerable = foo is IEnumerable<string>;
bool isBarIEnumerable = bar is IEnumerable<string>;
bool isFooList = foo is List<string>;
bool isBarList = bar is List<string>;