本文整理汇总了C#中List.InsertRange方法的典型用法代码示例。如果您正苦于以下问题:C# List.InsertRange方法的具体用法?C# List.InsertRange怎么用?C# List.InsertRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.InsertRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitClassDeclaration
protected override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
var newTypeDeclaration = (TypeDeclarationSyntax)base.VisitClassDeclaration(node);
if (_fields.Count > 0 || _methods.Count > 0)
{
var members = new List<MemberDeclarationSyntax>(newTypeDeclaration.Members);
members.InsertRange(0, _methods);
members.InsertRange(0, _fields);
return ((ClassDeclarationSyntax)newTypeDeclaration).Update(
newTypeDeclaration.Attributes,
newTypeDeclaration.Modifiers,
newTypeDeclaration.Keyword,
newTypeDeclaration.Identifier,
newTypeDeclaration.TypeParameterListOpt,
newTypeDeclaration.BaseListOpt,
newTypeDeclaration.ConstraintClauses,
newTypeDeclaration.OpenBraceToken,
Syntax.List(members.AsEnumerable()),
newTypeDeclaration.CloseBraceToken,
newTypeDeclaration.SemicolonTokenOpt);
}
return newTypeDeclaration;
}
示例2: GetAllArt
public List<string> GetAllArt()
{
List<string> paths = new List<string>();
paths.InsertRange(0, GetPlaylistArt());
paths.InsertRange(paths.Count - 1, GetAlbumArt());
return paths;
}
示例3: GetBytes
/// <summary>
/// Gets the bytes matching the expected Kafka structure.
/// </summary>
/// <returns>The byte array of the request.</returns>
public override byte[] GetBytes()
{
List<byte> encodedMessageSet = new List<byte>();
encodedMessageSet.AddRange(GetInternalBytes());
byte[] requestBytes = BitWorks.GetBytesReversed(Convert.ToInt16((int)RequestType.Produce));
encodedMessageSet.InsertRange(0, requestBytes);
encodedMessageSet.InsertRange(0, BitWorks.GetBytesReversed(encodedMessageSet.Count));
return encodedMessageSet.ToArray();
}
示例4: GetMatchingArtifactsFrom
/// <summary>
/// Returns Artifacts files'information list from a given folder respecting include and exclude pattern
/// </summary>
/// <param name="directoryPath"></param>
/// <param name="includePatterns"></param>
/// <param name="excludePatterns"></param>
public static IList<FileInfo> GetMatchingArtifactsFrom(string directoryPath, string includePatterns, string excludePatterns)
{
var fileInfos = new List<FileInfo>();
if (Directory.Exists((directoryPath)))
{
var includeFiles = new List<string>();
if (!string.IsNullOrEmpty(includePatterns))
{
foreach (var includePattern in includePatterns.Split(','))
{
if (includePattern.Contains(@"\") || includePattern.Contains(@"/"))
{
var regex = WildcardToRegex(includePattern);
includeFiles.InsertRange(0,
Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories)
.Where(x => Regex.IsMatch(x, regex)));
;
}
else
{
includeFiles.InsertRange(0,
Directory.GetFiles(directoryPath, includePattern, SearchOption.AllDirectories));
}
}
}
var exludeFiles= new List<string>();
if (!string.IsNullOrEmpty(excludePatterns))
{
foreach (var excludePattern in excludePatterns.Split(','))
{
if (excludePattern.Contains(@"/") || excludePattern.Contains(@"\"))
{
var regex = WildcardToRegex(excludePattern);
exludeFiles.InsertRange(0,
Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories)
.Where(x => Regex.IsMatch(x, regex)));
}
else
{
exludeFiles.InsertRange(0,
Directory.GetFiles(directoryPath, excludePattern, SearchOption.AllDirectories));
}
}
}
fileInfos = includeFiles.Except(exludeFiles)
.Select(x=> new FileInfo(x)).ToList();
}
return fileInfos;
}
示例5: ToByteArray
private byte[] ToByteArray()
{
List<byte> messageBytes = new List<byte>();
foreach (STUNAttributeTLV attribute in this.Attributes)
{
messageBytes.InsertRange(messageBytes.Count, attribute.Bytes);
MessageHeader.Length += attribute.Length;
}
messageBytes.InsertRange(0, MessageHeader.Bytes);
return messageBytes.ToArray();
}
示例6: Main
public static void Main(string[] args)
{
Dictionary<string,int> dict=new Dictionary<string,int>();
dict.Add("one",1);
dict.Add("two",2);
dict.Add("three",3);
dict.Add("four",4);
dict.Remove("one");
Console.WriteLine(dict.ContainsKey("dsaf"));
Console.WriteLine("Key Value Pairs after Dictionary related operations:");
foreach (var pair in dict)
{
Console.WriteLine("{0}, {1}",
pair.Key,
pair.Value);
}
dict.Clear ();
List<string> strList = new List<string> ();
strList.Add ("one");
strList.Add ("two");
strList.Add ("three");
strList.Add ("four");
strList.Add ("five");
strList.Insert (3, "great");
string[] newList = new string[3]{ "ten", "eleven", "twelve" };
strList.AddRange (newList);
strList.InsertRange (3, newList);
Console.WriteLine ("Output after all list related operations i.e. add, insert, addrange, insertrange,remove");
foreach (var i in strList)
Console.WriteLine (i);
}
示例7: Main
public static void Main () {
List<int> array = new List<int> { 1, 2, 3 };
List<int> array2 = new List<int> { 4, 5, 6 };
array.InsertRange(1, array2);
foreach (var member in array)
Console.WriteLine(member);
}
示例8: Write
public byte[] Write(ScenarioFile file)
{
var scenarioData = new List<byte>();
scenarioData.AddRange(Encoding.ASCII.GetBytes("SCENARIO\r\n"));
scenarioData.AddRange(BitConverter.GetBytes(Version));
scenarioData.AddRange(BitConverter.GetBytes(file.ContentFiles.Count));
file.ContentFiles[0] = CreateAreaSubFile(file.ZoneData);
var ndfBinWriter = new NdfbinWriter();
file.ContentFiles[1] = ndfBinWriter.Write(file.NdfBinary, false);
foreach (var contentFile in file.ContentFiles)
{
scenarioData.AddRange(BitConverter.GetBytes(contentFile.Length));
scenarioData.AddRange(contentFile);
}
byte[] hash = MD5.Create().ComputeHash(scenarioData.ToArray());
scenarioData.InsertRange(10, hash.Concat(new byte[] { 0x00, 0x00 }));
return scenarioData.ToArray();
}
示例9: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Insert the collection to the beginning of the list");
try
{
string[] strArray = { "apple", "dog", "banana", "chocolate", "dog", "food" };
List<string> listObject = new List<string>(strArray);
string[] insert = { "Hello", "World" };
listObject.InsertRange(0, insert);
if (listObject.Count != 8)
{
TestLibrary.TestFramework.LogError("003", "The result is not the value as expected,Count is: " + listObject.Count);
retVal = false;
}
if ((listObject[0] != "Hello") || (listObject[1] != "World"))
{
TestLibrary.TestFramework.LogError("004", "The result is not the value as expected");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例10: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: The generic type is int");
try
{
int[] iArray = { 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14 };
List<int> listObject = new List<int>(iArray);
int[] insert = { 4, 5, 6, 7 };
listObject.InsertRange(4, insert);
for (int i = 0; i < 15; i++)
{
if (listObject[i] != i)
{
TestLibrary.TestFramework.LogError("001", "The result is not the value as expected,listObject is: " + listObject[i]);
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例11: Main
static void Main(string[] args)
{
List<string> words = new List<string>(); // New string-typed list
words.Add("melon");
words.Add("avocado");
words.AddRange(new[] { "banana", "plum" });
words.Insert(0, "lemon"); // Insert at start
words.InsertRange(0, new[] { "peach", "nashi" }); // Insert at start
words.Remove("melon");
words.RemoveAt(3); // Remove the 4th element
words.RemoveRange(0, 2); // Remove first 2 elements
words.RemoveAll(s => s.StartsWith("n"));// Remove all strings starting in 'n'
Console.WriteLine(words[0]); // first word
Console.WriteLine(words[words.Count - 1]); // last word
foreach (string s in words) Console.WriteLine(s); // all words
List<string> subset = words.GetRange(1, 2); // 2nd->3rd words
string[] wordsArray = words.ToArray(); // Creates a new typed array
string[] existing = new string[1000];// Copy first two elements to the end of an existing array
words.CopyTo(0, existing, 998, 2);
List<string> upperCastWords = words.ConvertAll(s => s.ToUpper());
List<int> lengths = words.ConvertAll(s => s.Length);
ArrayList al = new ArrayList();
al.Add("hello");
string first = (string)al[0];
string[] strArr = (string[])al.ToArray(typeof(string));
List<string> list = al.Cast<string>().ToList();
}
示例12: ExpandControlFlowExpressions
public List<AphidExpression> ExpandControlFlowExpressions(List<AphidExpression> ast)
{
var ast2 = new List<AphidExpression>(ast);
var ifs = ast
.Select(x => new
{
Expression = x,
Expanded = ExpandControlFlowExpressions(x),
})
.Where(x => x.Expanded != null)
.ToArray();
foreach (var expandedIf in ifs)
{
var i = ast2.IndexOf(expandedIf.Expression);
ast2.RemoveAt(i);
ast2.InsertRange(i, expandedIf.Expanded);
}
if (AnyControlFlowExpressions(ast2))
{
return ExpandControlFlowExpressions(ast2);
}
else
{
//foreach (var n in ast.OfType<IParentNode>())
//{
// ExpandControlFlowExpressions(n.GetChildren().ToList());
//}
return ast2;
}
}
示例13: CombineFiles
public static byte[] CombineFiles(FileEx[] data)
{
List<byte> result = new List<byte>();
// Generating the header
int pos = 0;
string toAdd = "";
foreach(var file in data)
{
int future = pos + file.data.Length;
toAdd += string.Format("[|{0}|{1}|{2}|]", file.name, pos, file.data.Length);
pos = future;
}
result.AddRange(GetBytes(toAdd));
//Adding the header's size
result.InsertRange(0, BitConverter.GetBytes(result.Count));
//Adding the file data
foreach(var file in data)
{
result.AddRange(file.data);
}
return result.ToArray();
}
示例14: Send
public void Send(string name, string content)
{
// Sends text EV3Packet in this format:
// bbbbmmmmttssllaaaLLLLppp
// bbbb = bytes in the message, little endian
// mmmm = message counter
// tt = 0×81
// ss = 0x9E
// ll = mailbox name length INCLUDING the \0 terminator
// aaa… = mailbox name, should be terminated with a \0
// LLLL = payload length INCLUDING the , little endian
// ppp… = payload, should be terminated with the \0
List<byte> MessageHeaderList = new List<byte>();
MessageHeaderList.AddRange(new byte[] { 0x00, 0x01, 0x81, 0x9E }); // mmmmm + tt + ss
List<byte> by = BitConverter.GetBytes((Int16)(name.Length + 1)).Reverse().ToList();
by.RemoveAt(0);
MessageHeaderList.AddRange(by.ToArray()); // ll
MessageHeaderList.AddRange(Encoding.ASCII.GetBytes(name)); // aaa…
MessageHeaderList.AddRange(new byte[] { 0x00 }); // \0
MessageHeaderList.AddRange(BitConverter.GetBytes((Int16)(content.Length + 1))); // LLLL
MessageHeaderList.AddRange(Encoding.ASCII.GetBytes(content)); // ppp…
MessageHeaderList.AddRange(new byte[] { 0x00 }); // \0
MessageHeaderList.InsertRange(0, BitConverter.GetBytes((Int16)(MessageHeaderList.Count))); // bbbb
EV3ComPort.Write(MessageHeaderList.ToArray(), 0, MessageHeaderList.ToArray().Length);
}
示例15: GetAllDirectories
// Method to retrieve all directories, recursively, within a store.
public static List<String> GetAllDirectories(string pattern, IsolatedStorageFile storeFile)
{
// Get the root of the search string.
string root = Path.GetDirectoryName(pattern);
if (root != "")
{
root += "/";
}
// Retrieve directories.
List<String> directoryList = new List<String>(storeFile.GetDirectoryNames(pattern));
// Retrieve subdirectories of matches.
for (int i = 0, max = directoryList.Count; i < max; i++)
{
string directory = directoryList[i] + "/";
List<String> more = GetAllDirectories(root + directory + "*", storeFile);
// For each subdirectory found, add in the base path.
for (int j = 0; j < more.Count; j++)
{
more[j] = directory + more[j];
}
// Insert the subdirectories into the list and
// update the counter and upper bound.
directoryList.InsertRange(i + 1, more);
i += more.Count;
max += more.Count;
}
return directoryList;
}