|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Metodo Enumerable.Concat<TSource>
Spazio dei nomi: System.Linq
Assembly: System.Core (in System.Core.dll)
public static IEnumerable<TSource> Concat<TSource>( this IEnumerable<TSource> first, IEnumerable<TSource> second )
Parametri di tipo
- TSource
Tipo degli elementi delle sequenze di input.
Parametri
- first
- Tipo: System.Collections.Generic.IEnumerable<TSource>
Prima sequenza da concatenare.
- second
- Tipo: System.Collections.Generic.IEnumerable<TSource>
Sequenza da concatenare alla prima sequenza.
Valore restituito
Tipo: System.Collections.Generic.IEnumerable<TSource>Nota sull'utilizzo
In Visual Basic e C# è possibile chiamare questo metodo come metodo di istanza su qualsiasi oggetto di tipo IEnumerable<TSource>. Per chiamare il metodo utilizzando la sintassi del metodo di istanza, omettere il primo parametro. Per ulteriori informazioni, vedere Metodi di estensione (Visual Basic) o Metodi di estensione (Guida per programmatori C#).| Eccezione | Condizione |
|---|---|
| ArgumentNullException |
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
static Pet[] GetCats()
{
Pet[] cats = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
return cats;
}
static Pet[] GetDogs()
{
Pet[] dogs = { new Pet { Name="Bounder", Age=3 },
new Pet { Name="Snoopy", Age=14 },
new Pet { Name="Fido", Age=9 } };
return dogs;
}
public static void ConcatEx1()
{
Pet[] cats = GetCats();
Pet[] dogs = GetDogs();
IEnumerable<string> query =
cats.Select(cat => cat.Name).Concat(dogs.Select(dog => dog.Name));
foreach (string name in query)
{
Console.WriteLine(name);
}
}
// This code produces the following output:
//
// Barley
// Boots
// Whiskers
// Bounder
// Snoopy
// Fido
Pet[] cats = GetCats();
Pet[] dogs = GetDogs();
IEnumerable<string> query =
new[] { cats.Select(cat => cat.Name), dogs.Select(dog => dog.Name) }
.SelectMany(name => name);
foreach (string name in query)
{
Console.WriteLine(name);
}
// This code produces the following output:
//
// Barley
// Boots
// Whiskers
// Bounder
// Snoopy
// Fido
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.