本文整理匯總了C#中System.Collections.Generic.List<T>.GetRange方法的典型用法代碼示例。如果您正苦於以下問題:C# List<T>.GetRange方法的具體用法?C# List<T>.GetRange怎麽用?C# List<T>.GetRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Generic.List<T>
的用法示例。
在下文中一共展示了List<T>.GetRange方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
string[] input = { "Brachiosaurus",
"Amargasaurus",
"Mamenchisaurus" };
List<string> dinosaurs = new List<string>(input);
Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
Console.WriteLine("\nAddRange(dinosaurs)");
dinosaurs.AddRange(dinosaurs);
Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
Console.WriteLine("\nRemoveRange(2, 2)");
dinosaurs.RemoveRange(2, 2);
Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
input = new string[] { "Tyrannosaurus",
"Deinonychus",
"Velociraptor"};
Console.WriteLine("\nInsertRange(3, input)");
dinosaurs.InsertRange(3, input);
Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
Console.WriteLine("\noutput = dinosaurs.GetRange(2, 3).ToArray()");
string[] output = dinosaurs.GetRange(2, 3).ToArray();
Console.WriteLine();
foreach( string dinosaur in output )
{
Console.WriteLine(dinosaur);
}
}
}
輸出:
Capacity: 3 Brachiosaurus Amargasaurus Mamenchisaurus AddRange(dinosaurs) Brachiosaurus Amargasaurus Mamenchisaurus Brachiosaurus Amargasaurus Mamenchisaurus RemoveRange(2, 2) Brachiosaurus Amargasaurus Amargasaurus Mamenchisaurus InsertRange(3, input) Brachiosaurus Amargasaurus Amargasaurus Tyrannosaurus Deinonychus Velociraptor Mamenchisaurus output = dinosaurs.GetRange(2, 3).ToArray() Amargasaurus Tyrannosaurus Deinonychus