本文整理汇总了C#中System.Collections.Generic.List<T>.RemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# List<T>.RemoveRange方法的具体用法?C# List<T>.RemoveRange怎么用?C# List<T>.RemoveRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List<T>
的用法示例。
在下文中一共展示了List<T>.RemoveRange方法的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