本文整理汇总了C#中StringCollection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# StringCollection.Insert方法的具体用法?C# StringCollection.Insert怎么用?C# StringCollection.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringCollection
的用法示例。
在下文中一共展示了StringCollection.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertTest
public static void InsertTest(StringCollection collection, string[] data, string element, int location)
{
collection.Insert(location, element);
Assert.Equal(data.Length + 1, collection.Count);
if (element == ElementNotPresent)
{
Assert.Equal(location, collection.IndexOf(ElementNotPresent));
}
for (int i = 0; i < data.Length + 1; i++)
{
if (i < location)
{
Assert.Equal(data[i], collection[i]);
}
else if (i == location)
{
Assert.Equal(element, collection[i]);
}
else
{
Assert.Equal(data[i - 1], collection[i]);
}
}
}
示例2: Insert_ArgumentInvalidTest
public static void Insert_ArgumentInvalidTest(StringCollection collection, string[] data)
{
Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(-1, ElementNotPresent));
Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(data.Length + 1, ElementNotPresent));
// And as explicit interface implementation
Assert.Throws<ArgumentOutOfRangeException>(() => ((IList)collection).Insert(-1, ElementNotPresent));
Assert.Throws<ArgumentOutOfRangeException>(() => ((IList)collection).Insert(data.Length + 1, ElementNotPresent));
}
示例3: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringCollection sc;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sc = new StringCollection();
Console.WriteLine("1. Insert into empty collection");
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (sc.Count > 0)
sc.Clear();
sc.Insert(0, values[i]);
if (sc.Count != 1)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}a, Count {1} instead of 1", i, sc.Count);
}
if (! sc.Contains(values[i]))
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}b, doesn't contain just inserted item", i);
}
}
Console.WriteLine("2. Insert into filled collection");
strLoc = "Loc_002oo";
Console.WriteLine(" - at the beginning");
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
}
string val = intl.GetString(MAX_LEN, true, true, true);
iCountTestcases++;
sc.Insert(0, val);
if (sc.Count != values.Length + 1)
{
iCountErrors++;
Console.WriteLine("Err_0002b, Count returned {0} instead of {1}", sc.Count, values.Length + 1);
}
iCountTestcases++;
if (sc.IndexOf(val) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002c, IndexOf returned {0} instead of {1}", sc.IndexOf(val), 0);
}
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (sc.IndexOf(values[i]) != i+1)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}d, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i+1);
}
}
Console.WriteLine(" - at the end");
iCountTestcases++;
sc.Clear();
sc.AddRange(values);
if (sc.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002e, count is {0} instead of {1}", sc.Count, values.Length);
}
iCountTestcases++;
sc.Insert(values.Length, val);
if (sc.Count != values.Length + 1)
{
iCountErrors++;
Console.WriteLine("Err_0002f, Count returned {0} instead of {1}", sc.Count, values.Length + 1);
}
iCountTestcases++;
if (sc.IndexOf(val) != values.Length)
{
//.........这里部分代码省略.........