本文整理汇总了C#中SortedList.SetByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.SetByIndex方法的具体用法?C# SortedList.SetByIndex怎么用?C# SortedList.SetByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.SetByIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
//.........这里部分代码省略.........
strLoc = "Loc_63rfdg";
try
{
iCountTestcases++;
slst1[null] = "Not a chance";
iCountErrors++;
Console.WriteLine("Err_7439dg! Exception not thrown");
}
catch(ArgumentNullException)
{
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_7653dsv! Unexpected exception thrown, " + ex);
}
strValue = null;
slst1[51] = strValue ;
if(slst1[51] != null)
{
iCountErrors++;
Console.WriteLine("Err_752dsg! Expected value not returned, " + slst1[51]);
}
strLoc = "Loc_7435gfdsg";
iNumberOfElements = 10;
slst1 = new SortedList();
for(int i=iNumberOfElements-1; i>=0;i--)
{
slst1.Add(50 + i, "Value_" + i);
}
for(int i=0; i<slst1.Count;i++)
{
strValue = "Value_" + i + 50;
slst1.SetByIndex(i, strValue);
}
for(int i=0; i<slst1.Count;i++)
{
strValue = "Value_" + i + 50;
if(!strValue.Equals(slst1.GetByIndex(i)))
{
iCountErrors++;
Console.WriteLine("Err_003oo! Expected value not returned, " + strValue + " " + slst1.GetByIndex(i));
}
}
strLoc = "Loc_7645cfxgd";
try
{
iCountTestcases++;
slst1.SetByIndex(-1, strValue);
iCountErrors++;
Console.WriteLine("Err_7439dg! Exception not thrown");
}
catch(ArgumentOutOfRangeException)
{
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_0155234sfdg! Unexpected exception thrown, " + ex);
}
try
{
iCountTestcases++;
slst1.SetByIndex(slst1.Count, strValue);
iCountErrors++;
Console.WriteLine("Err_7439dg! Exception not thrown");
示例2: Test01
//.........这里部分代码省略.........
//already existent ones
strValue = "Value_1";
Assert.Equal(strValue, slst1[51]);
strValue = "Different value";
slst1[51] = strValue;
Assert.Equal(strValue, slst1[51]);
//paramter stuff
Assert.Throws<ArgumentNullException>(() =>
{
slst1[null] = "Not a chance";
}
);
strValue = null;
slst1[51] = strValue;
Assert.Null(slst1[51]);
//SetByIndex - this changes the value at this specific index. Note that SortedList
//does not have the equicalent Key changing means as this is a SortedList and will be done
//automatically!!!
iNumberOfElements = 10;
slst1 = new SortedList();
for (int i = iNumberOfElements - 1; i >= 0; i--)
{
slst1.Add(50 + i, "Value_" + i);
}
for (int i = 0; i < slst1.Count; i++)
{
strValue = "Value_" + i + 50;
slst1.SetByIndex(i, strValue);
}
for (int i = 0; i < slst1.Count; i++)
{
strValue = "Value_" + i + 50;
Assert.Equal(strValue, slst1.GetByIndex(i));
}
//paramter stuff
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
slst1.SetByIndex(-1, strValue);
}
);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
slst1.SetByIndex(slst1.Count, strValue);
}
);
//CopyTo() - copies the values
iNumberOfElements = 10;
slst1 = new SortedList();
for (int i = iNumberOfElements - 1; i >= 0; i--)
{
slst1.Add(50 + i, "Value_" + i);
}
ar1 = new DictionaryEntry[iNumberOfElements];
slst1.CopyTo(ar1, 0);