本文整理汇总了C#中StringCollection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# StringCollection.RemoveAt方法的具体用法?C# StringCollection.RemoveAt怎么用?C# StringCollection.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringCollection
的用法示例。
在下文中一共展示了StringCollection.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveAt_ArgumentInvalidTest
public static void RemoveAt_ArgumentInvalidTest(StringCollection collection, string[] data)
{
Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(data.Length));
}
示例2: GetEnumerator_ModifiedCollectionTest
public static void GetEnumerator_ModifiedCollectionTest(StringCollection collection, string[] data)
{
StringEnumerator enumerator = collection.GetEnumerator();
Assert.NotNull(enumerator);
if (data.Length > 0)
{
Assert.True(enumerator.MoveNext());
string current = enumerator.Current;
Assert.Equal(data[0], current);
collection.RemoveAt(0);
if (data.Length > 1 && data[0] != data[1])
{
Assert.NotEqual(current, collection[0]);
}
Assert.Equal(current, enumerator.Current);
Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
Assert.Throws<InvalidOperationException>(() => enumerator.Reset());
}
else
{
collection.Add("newValue");
Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
}
}
示例3: RemoveAtTest
public static void RemoveAtTest(StringCollection collection, string[] data, int location)
{
collection.RemoveAt(location);
Assert.Equal(data.Length - 1, collection.Count);
for (int i = 0; i < data.Length - 1; i++)
{
if (i < location)
{
Assert.Equal(data[i], collection[i]);
}
else if (i >= location)
{
Assert.Equal(data[i + 1], collection[i]);
}
}
}
示例4: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the extra parameters
/// </summary>
/// <param name="parameters">The parameters for the property.</param>
public override void DeserializeParameters(StringCollection parameters)
{
string[] delVals, memberVals;
string tempVal;
int idx;
if(parameters == null || parameters.Count == 0)
return;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
{
for(idx = 0; idx < ntv.Length; idx++)
if(ntv[idx].IsMatch(parameters[paramIdx]))
break;
if(idx == ntv.Length)
{
// If it was a parameter name, skip the value too
if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal))
paramIdx++;
continue; // Not an attendee parameter
}
// Parameters may appear as a pair (name followed by value) or by value alone
switch(ntv[idx].EnumValue)
{
case ParameterType.Role:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
role = parameters[paramIdx];
break;
case ParameterType.Rsvp:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
tempVal = parameters[paramIdx].Trim();
rsvp = (String.Compare(tempVal, "YES", StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(tempVal, "TRUE", StringComparison.OrdinalIgnoreCase) == 0);
}
break;
case ParameterType.Expect:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
expect = parameters[paramIdx];
break;
case ParameterType.CalendarUserType:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
cuType = parameters[paramIdx];
break;
case ParameterType.DelegatedFrom:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
delVals = parameters[paramIdx].Split(',');
delFrom.Clear();
foreach(string s in delVals)
{
tempVal = s.Trim();
if(tempVal.Length > 0)
delFrom.Add(tempVal);
}
}
break;
case ParameterType.DelegatedTo:
if(!ntv[idx].IsParameterValue)
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
delVals = parameters[paramIdx].Split(',');
delTo.Clear();
foreach(string s in delVals)
{
//.........这里部分代码省略.........
示例5: 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. RemoveAt() from empty collection");
iCountTestcases++;
if (sc.Count > 0)
sc.Clear();
try
{
sc.RemoveAt(0);
iCountErrors++;
Console.WriteLine("Err_0001_{0}a, no exception");
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}b, unexpected exception: " + e.ToString());
}
Console.WriteLine("2. RemoveAt() on 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);
}
iCountTestcases++;
sc.RemoveAt(0);
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.Contains(values[0]))
{
iCountErrors++;
Console.WriteLine("Err_0002c, removed wrong item");
}
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.RemoveAt(values.Length-1);
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.Contains(values[values.Length - 1]))
{
//.........这里部分代码省略.........
示例6: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the TYPE parameter
/// </summary>
/// <param name="parameters">The parameters for the property</param>
public override void DeserializeParameters(StringCollection parameters)
{
string[] types;
int idx, subIdx;
if(parameters == null || parameters.Count == 0)
return;
EMailTypes et = EMailTypes.None;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
{
for(idx = 0; idx < ntv.Length; idx++)
if(ntv[idx].IsMatch(parameters[paramIdx]))
break;
if(idx == ntv.Length)
{
// If it was a parameter name, skip the value too
if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal))
paramIdx++;
continue; // Not an e-mail parameter
}
// Parameters may appear as a pair (name followed by value) or by value alone
if(!ntv[idx].IsParameterValue && paramIdx < parameters.Count - 1)
{
// Remove the TYPE parameter name so that the base class won't put it in the custom
// parameters. We'll skip this one and decode the parameter value.
parameters.RemoveAt(paramIdx);
// If the values contain a comma, split it on the comma and parse the types (i.e. vCard 3.0
// spec). If not, just continue and handle it as normal.
if(reSplit.IsMatch(parameters[paramIdx]))
{
types = reSplit.Split(parameters[paramIdx]);
foreach(string s in types)
{
for(subIdx = 1; subIdx < ntv.Length; subIdx++)
if(ntv[subIdx].IsMatch(s))
break;
// Unrecognized ones are ignored
if(subIdx < ntv.Length)
et |= ntv[subIdx].EnumValue;
}
parameters.RemoveAt(paramIdx);
}
}
else
{
et |= ntv[idx].EnumValue;
// As above, remove the value
parameters.RemoveAt(paramIdx);
}
paramIdx--;
}
if(et != EMailTypes.None)
this.EMailTypes = et;
// Let the base class handle all other parameters
base.DeserializeParameters(parameters);
}
示例7: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the CONTEXT parameter
/// </summary>
/// <param name="parameters">The parameters for the property</param>
public override void DeserializeParameters(StringCollection parameters)
{
if(parameters == null || parameters.Count == 0)
return;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
if(String.Compare(parameters[paramIdx], "CONTEXT=", StringComparison.OrdinalIgnoreCase) == 0)
{
// Remove the parameter name
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
this.Context = parameters[paramIdx];
// As above, remove the value
parameters.RemoveAt(paramIdx);
}
break;
}
// Let the base class handle all other parameters
base.DeserializeParameters(parameters);
}
示例8: deleteBookmark
private void deleteBookmark(int num)
{
StringCollection sc = new StringCollection();
FileStream aFile = new FileStream(bookmarkFile, FileMode.Open);
StreamReader sr = new StreamReader(aFile);
string strLine = sr.ReadLine();
while(strLine != null) {
sc.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
aFile.Close();
if (num - 1 > -1) {
sc.RemoveAt(num - 1);
String[] bookmarks = new String[sc.Count];
sc.CopyTo(bookmarks, 0);
File.WriteAllLines(bookmarkFile, bookmarks);
}
}
示例9: runTest
//.........这里部分代码省略.........
}
iCountTestcases++;
if (String.Compare(en.Current, sc[0], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002r, Current returned wrong value");
}
Console.WriteLine(" - Current after Reset()");
iCountTestcases++;
en.Reset();
try
{
curr = en.Current;
iCountErrors++;
Console.WriteLine("Err_0002s, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0002t, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("3. Reset() modified collection in process of enumeration");
strLoc = "Loc_003oo";
iCountTestcases++;
if (sc.Count < 1)
sc.AddRange(values);
iCountTestcases++;
en = sc.GetEnumerator();
Console.WriteLine(" - Reset() for init position of the enumerator");
sc.RemoveAt(0);
iCountTestcases++;
try
{
en.Reset();
iCountErrors++;
Console.WriteLine("Err_0003a, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0003b, unexpected exception: {0}", e.ToString());
}
en = sc.GetEnumerator();
Console.WriteLine(" - Enumerate to the middle of the collection and Reset()");
for (int i = 0; i < sc.Count / 2; i++)
{
iCountTestcases++;
res = en.MoveNext();
}
Console.WriteLine(" - modify collection");
curr = en.Current;
iCountTestcases++;
sc.RemoveAt(0);
Console.WriteLine(" - get Current");
iCountTestcases++;
if (String.Compare(curr, en.Current) != 0 )
{
iCountErrors++;
示例10: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the TYPE parameter
/// </summary>
/// <param name="parameters">The parameters for the property</param>
public override void DeserializeParameters(StringCollection parameters)
{
int idx;
if(parameters == null || parameters.Count == 0)
return;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
{
for(idx = 0; idx < ntv.Length; idx++)
if(ntv[idx].IsMatch(parameters[paramIdx]))
break;
if(idx == ntv.Length)
{
// If it was a parameter name, skip the value too
if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal))
paramIdx++;
continue; // Not a photo parameter
}
// Parameters may appear as a pair (name followed by value) or by value alone
if(!ntv[idx].IsParameterValue)
{
// Remove the TYPE parameter name so that the base class won't put it in the custom
// parameters. We'll skip this one and decode the parameter value.
parameters.RemoveAt(paramIdx);
}
else
{
this.ImageType = parameters[paramIdx];
// As above, remove the value
parameters.RemoveAt(paramIdx);
}
paramIdx--;
}
// Let the base class handle all other parameters
base.DeserializeParameters(parameters);
}
示例11: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the FBTYPE parameter
/// </summary>
/// <param name="parameters">The parameters for the property</param>
public override void DeserializeParameters(StringCollection parameters)
{
string type;
if(parameters == null || parameters.Count == 0)
return;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
if(String.Compare(parameters[paramIdx], "FBTYPE=", StringComparison.OrdinalIgnoreCase) == 0)
{
// Remove the parameter name
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
type = parameters[paramIdx].Trim().ToUpperInvariant();
switch(type)
{
case "FREE":
this.FreeBusyType = FreeBusyType.Free;
break;
case "BUSY":
this.FreeBusyType = FreeBusyType.Busy;
break;
case "BUSY-UNAVAILABLE":
this.FreeBusyType = FreeBusyType.BusyUnavailable;
break;
case "BUSY-TENTATIVE":
this.FreeBusyType = FreeBusyType.BusyTentative;
break;
default:
this.OtherType = parameters[paramIdx];
break;
}
// As above, remove the value
parameters.RemoveAt(paramIdx);
}
break;
}
// Let the base class handle all other parameters
base.DeserializeParameters(parameters);
}
示例12: runTest
//.........这里部分代码省略.........
Console.WriteLine("Err_0002h, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0002j, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("3. Enumerator and modified collection in the middle of enumeration");
strLoc = "Loc_003oo";
iCountTestcases++;
if (sc.Count < 1)
sc.AddRange(values);
iCountTestcases++;
en = sc.GetEnumerator();
Console.WriteLine(" - Enumerate to the middle of the collection");
for (int i = 0; i < sc.Count / 2; i++)
{
iCountTestcases++;
res = en.MoveNext();
if (!res)
{
iCountErrors++;
Console.WriteLine("Err_0003a_{0}, MoveNext returned false", i);
}
}
Console.WriteLine(" - modify collection");
cnt = sc.Count;
curr = en.Current;
iCountTestcases++;
sc.RemoveAt(0);
if ( sc.Count != cnt - 1 )
{
iCountErrors++;
Console.WriteLine("Err_0003b, didn't remove 0-item");
}
Console.WriteLine(" - get Current");
iCountTestcases++;
if (String.Compare(curr, en.Current) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003c, current returned {0} instead of {1}", en.Current, curr);
}
Console.WriteLine(" - call MoveNext");
iCountTestcases++;
try
{
res = en.MoveNext();
iCountErrors++;
Console.WriteLine("Err_0003d, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0003e, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("4. Enumerator and collection modified after enumeration");
strLoc = "Loc_004oo";
iCountTestcases++;
示例13: LayersFromString
private static Dictionary<String, StringCollection> LayersFromString(string value)
{
Dictionary<String, StringCollection> dict = new Dictionary<String, StringCollection>();
if (value.Length > 0)
{
string[] layers = value.Split(Separator2);
for (int i = 0; i < layers.Length; ++i)
{
StringCollection values = new StringCollection();
values.AddRange(layers[i].Split(Separator3));
string key = values[0];
values.RemoveAt(0);
dict.Add(key, values);
}
}
return dict;
}
示例14: DeserializeParameters
/// <summary>
/// This is overridden to provide custom handling of the RELTYPE parameter
/// </summary>
/// <param name="parameters">The parameters for the property</param>
public override void DeserializeParameters(StringCollection parameters)
{
string type;
if(parameters == null || parameters.Count == 0)
return;
for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
if(String.Compare(parameters[paramIdx], "RELTYPE=", StringComparison.OrdinalIgnoreCase) == 0)
{
// Remove the parameter name
parameters.RemoveAt(paramIdx);
if(paramIdx < parameters.Count)
{
type = parameters[paramIdx].Trim().ToUpperInvariant();
switch(type)
{
case "PARENT":
this.RelationshipType = RelationshipType.Parent;
break;
case "CHILD":
this.RelationshipType = RelationshipType.Child;
break;
case "SIBLING":
this.RelationshipType = RelationshipType.Sibling;
break;
default:
this.OtherRelationship = parameters[paramIdx];
break;
}
// As above, remove the value
parameters.RemoveAt(paramIdx);
}
break;
}
// Let the base class handle all other parameters
base.DeserializeParameters(parameters);
}
示例15: LoadGridWithItems
//=====================================================================
/// <summary>
/// Load the grid with the specified calendar items
/// </summary>
private void LoadGridWithItems()
{
int gridIdx = dgvCalendar.CurrentCellAddress.Y;
VCalendar.TimeZones.Sort(true);
dgvCalendar.DataSource = null;
// Get just the time zones used?
if(chkLimitToCalendar.Checked)
{
// Get just the time zones used
StringCollection timeZonesUsed = new StringCollection();
if(vCal != null)
{
vCal.TimeZonesUsed(timeZonesUsed);
// Remove entries that don't exist
for(int idx = 0; idx < timeZonesUsed.Count; idx++)
if(VCalendar.TimeZones[timeZonesUsed[idx]] == null)
{
timeZonesUsed.RemoveAt(idx);
idx--;
}
}
// Add each instance to a temporary collection and bind it to the grid
timeZones.Clear();
foreach(string timeZoneId in timeZonesUsed)
timeZones.Add(VCalendar.TimeZones[timeZoneId]);
dgvCalendar.DataSource = timeZones;
}
else
dgvCalendar.DataSource = VCalendar.TimeZones;
// Enable or disable the buttons based on the vCard count
btnEdit.Enabled = btnDelete.Enabled = (dgvCalendar.RowCount != 0);
// Stay on the last item selected
if(gridIdx > -1 && gridIdx < dgvCalendar.RowCount)
dgvCalendar.CurrentCell = dgvCalendar[0, gridIdx];
}