本文整理汇总了C#中Collection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.RemoveAt方法的具体用法?C# Collection.RemoveAt怎么用?C# Collection.RemoveAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShuffleList
public static string[] ShuffleList(string[] list)
{
if (list.Length <= 1)
return list;
// Convert list to collection
Collection<string> collection = new Collection<string>();
foreach (string str in list)
{
collection.Add(str);
}
string[] randomList = new string[collection.Count];
Random r = new Random(DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Millisecond);
int randomIndex = 0;
int currentIndex = 0;
while (collection.Count > 0)
{
randomIndex = r.Next(0, collection.Count); //Choose a random object in the list
randomList[currentIndex++] = collection[randomIndex]; //add it to the new, random list<
collection.RemoveAt(randomIndex); //remove to avoid duplicates
}
//clean up
collection.Clear();
collection = null;
r = null;
return randomList; //return the new random list
}
示例2: selectTargetsFromBoard
public Collection<Minion> selectTargetsFromBoard(Board board, Vector3 selectionPoint, int targetCount, float minRange, float maxRange, MinionStateSelection minionState)
{
Collection<Minion> minionsInRange = new Collection<Minion>();
Collection<Minion> minionsUnderAttack = new Collection<Minion>();
foreach (var v in board.minions)
{
if (v.Value.destroyable == true || (minionState != MinionStateSelection.ANY && ((v.Value.minionState == Minion.MinionState.DEAD && minionState == MinionStateSelection.ALIVE)
|| (v.Value.minionState == Minion.MinionState.ALIVE && minionState == MinionStateSelection.DEAD))))
continue;
Vector3 minionCoor = v.Value.getWorldPosition();
float dist = (selectionPoint - minionCoor).magnitude;
if (v.Value.isUntargetable() == false && dist >= minRange && dist <= maxRange)
minionsInRange.Add(v.Value);
}
if (targetCount >= minionsInRange.Count)
return minionsInRange;
for (int i = 0; i < targetCount; i++)
{
if (minionsInRange.Count > 0)
{
float current = float.MinValue;
int index = -1;
for (int j = 0; j < minionsInRange.Count; j++)
{
Vector3 minionCoor = minionsInRange.ElementAt(j).getWorldPosition();
float dist = (selectionPoint - minionCoor).magnitude;
if (dist > current)
{
index = j;
current = dist;
}
}
if (index != -1)
{
minionsUnderAttack.Add(minionsInRange.ElementAt(index));
minionsInRange.RemoveAt(index);
}
}
else
return minionsUnderAttack;
}
return minionsUnderAttack;
}
示例3: SetFilterAttributeFilterProvider
private static void SetFilterAttributeFilterProvider(this IContainer container, Collection<IFilterProvider> filterProviders = null)
{
filterProviders = filterProviders ?? FilterProviders.Providers;
var filterAttributeFilterProviders = filterProviders.OfType<FilterAttributeFilterProvider>().ToArray();
for (var i = filterAttributeFilterProviders.Length - 1; i >= 0; --i)
{
filterProviders.RemoveAt(i);
}
var filterProvider = new DryIocFilterAttributeFilterProvider(container);
filterProviders.Add(filterProvider);
container.RegisterInstance<IFilterProvider>(filterProvider);
}
示例4: Run
public static void Run()
{
Collection<string> dinosaurs = new Collection<string>();
dinosaurs.Add("Psitticosaurus");
dinosaurs.Add("Caudipteryx");
dinosaurs.Add("Compsohnathus");
dinosaurs.Add("Muttaburrasaurus");
Console.WriteLine("{0} dinosaurs:", dinosaurs.Count);
Display(dinosaurs);
Console.WriteLine("\nIndexOf(\"Muttaburrasaurus\"): {0}", dinosaurs.IndexOf("Muttaburrasaurus"));
Console.WriteLine("\nContains(\"Caudipteryx\"): {0}", dinosaurs.Contains("Caudipteryx"));
Console.WriteLine("\nInsert(2, \"Nanotyrannus\")");
dinosaurs.Insert(2, "Nanotyrannus");
Display(dinosaurs);
Console.WriteLine("\ndinosaurs[2]: {0}", dinosaurs[2]);
Console.WriteLine("\ndinosaurs[2] = \"Microraptor\"");
dinosaurs[2] = "Microraptor";
Display(dinosaurs);
Console.WriteLine("\nRemove(\"Microraptor\")");
dinosaurs.Remove("Microraptor");
Display(dinosaurs);
Console.WriteLine("\nRemoveAt(0)");
dinosaurs.RemoveAt(0);
Display(dinosaurs);
Console.WriteLine("\ndinosaurs.Clear()");
dinosaurs.Clear();
Console.WriteLine("Count: {0}", dinosaurs.Count);
}
示例5: WriteFeaturesIntoQueue
private void WriteFeaturesIntoQueue(Collection<Feature> features, FeatureSource featureSource)
{
foreach (Feature feature in features)
{
Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
// Get the lineshape of the processing feature.
foreach (LineShape processingLineShape in processingLineShapes)
{
// Define a variable to save the points where the adjacent lines intersect with current processing line.
Collection<PointShape> crossingPoints = new Collection<PointShape>();
// Get all the lines in current processing shape bounds.
Collection<Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);
// Loop and see if the queried shape is intersected with processing shape.
foreach (Feature adjacentFeature in adjacentFeatures)
{
LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);
// The queried shape is intersected with processing shape.
foreach (PointShape point in tempCrossingPoints.Points)
{
bool hasAdded = false;
foreach (var item in crossingPoints)
{
if (point.X == item.X && point.Y == item.Y)
{
hasAdded = true;
break;
}
}
if (!hasAdded)
{
crossingPoints.Add(point);
}
}
}
// Order the crossing points following the sequence of line vertex.
Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);
Collection<Vertex> verteces = new Collection<Vertex>();
Collection<Feature> lineFeatures = new Collection<Feature>();
foreach (var vertex in vertecesOfNewLine)
{
verteces.Add(vertex.Vertex);
if (vertex.Flag)
{
if (verteces.Count >= 2)
{
LineShape segment = new LineShape(verteces);
lineFeatures.Add(new Feature(segment, feature.ColumnValues));
verteces.RemoveAt(0);
}
}
}
if (lineFeatures.Count > 0)
{
queue.Enqueue(lineFeatures);
}
}
#if DEBUG
Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, features.Count));
#endif
}
}
示例6: ExportEndpoint
/// <summary>
/// Writes custom Web Services Description Language (WSDL) elements into
/// the generated WSDL for an endpoint.
/// </summary>
public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
{
// We don't support more than one WSDL.
if (exporter.GeneratedWsdlDocuments.Count > 1)
{
Trace.TraceError(Resources.ExInconsistantXmlNamespaces);
throw new InvalidOperationException(Resources.ExInconsistantXmlNamespaces);
}
ServiceDescription wsdl =
exporter.GeneratedWsdlDocuments[0];
XmlSchemaSet schemaSet =
exporter.GeneratedXmlSchemas;
Collection<XmlSchema> importsList = new Collection<XmlSchema>();
for (int i = 0; i < wsdl.Types.Schemas.Count; i++)
{
XmlSchema schema = wsdl.Types.Schemas[i];
ResolveImportedSchemas(schema, schemaSet, importsList);
// If we don't have anything else (e.g. inlined types)
// in this schema, we can remove it.
if (schema.Includes.Count == 0 && schema.Items.Count == 0)
{
wsdl.Types.Schemas.RemoveAt(i--);
}
}
// Finally, add each of the real schemas we extracted in the above step.
while(importsList.Count != 0)
{
int l = importsList.Count - 1;
wsdl.Types.Schemas.Add(importsList[l]);
importsList.RemoveAt(l);
}
}
示例7: HandleArray
private void HandleArray(Plan p, Collection<int> path)
{
OutPortId newObjPort = new OutPortId(path, 0);
string newObjName = nameManager.foobar.Get(newObjPort);
Collection<string> args = new Collection<string>();
for (int i = 0; i < p.parameterChoosers.Length; i++)
{
Plan.ParameterChooser c = p.parameterChoosers[i];
path.Add(c.planIndex);
OutPortId paramPort = new OutPortId(path, c.resultIndex);
path.RemoveAt(path.Count - 1);
args.Add(nameManager.foobar.Get(paramPort));
}
b.Add(p.transformer.ToCSharpCode(new ReadOnlyCollection<string>(args), nameManager.foobar.Get(newObjPort)));
}
示例8: Visit
protected virtual void Visit(Plan p, Collection<int> path)
{
for (int i = 0; i < p.parentPlans.Length; i++)
{
Plan p2 = p.parentPlans[i];
path.Add(i);
Visit(p2, path);
path.RemoveAt(path.Count - 1);
}
nameManager.ProcessPlan(p, path);
}
示例9: MapOutputPortsConstructor
private void MapOutputPortsConstructor(Plan p, Collection<int> path, string freshvar)
{
// Map new object.
OutPortId newObjPort = new OutPortId(path, 0);
foobar.set(newObjPort, freshvar);
// Map mutated parameters.
for (int i = 0; i < p.parameterChoosers.Length; i++)
{
Plan.ParameterChooser c = p.parameterChoosers[i];
OutPortId pOutputPort = new OutPortId(path, i + 1);
path.Add(c.planIndex);
OutPortId paramPort = new OutPortId(path, c.resultIndex);
path.RemoveAt(path.Count - 1);
foobar.set(pOutputPort, foobar.Get(paramPort));
}
}
示例10: MoveDomainClassesToTop
private static Collection<ModelElement> MoveDomainClassesToTop(Collection<ModelElement> modelElements)
{
Collection<ModelElement> sortedME = new Collection<ModelElement>();
for (int i = modelElements.Count - 1; i >= 0; i--)
if (modelElements[i] is DomainClass)
{
sortedME.Insert(0, modelElements[i]);
modelElements.RemoveAt(i);
}
foreach (ModelElement m in modelElements)
sortedME.Add(m);
return sortedME;
}
示例11: TryImportTokenAssertion
public virtual bool TryImportTokenAssertion(MetadataImporter importer, PolicyConversionContext policyContext, Collection<XmlElement> assertions, out SecurityTokenParameters parameters, out bool isOptional)
{
parameters = null;
isOptional = false;
if (assertions.Count >= 1)
{
XmlElement tokenAssertion = assertions[0];
if (TryImportWsspKerberosTokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportWsspX509TokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportWsspUsernameTokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportWsspIssuedTokenAssertion(importer, policyContext, tokenAssertion, out parameters)
|| TryImportWsspSpnegoContextTokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportMsspSslContextTokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportWsspSecureConversationTokenAssertion(importer, tokenAssertion, out parameters)
|| TryImportWsspRsaTokenAssertion(importer, tokenAssertion, out parameters))
{
string optionalAttribute = tokenAssertion.GetAttribute(OptionalName, WspNamespace);
if (String.IsNullOrEmpty(optionalAttribute))
{
optionalAttribute = tokenAssertion.GetAttribute(OptionalName, Wsp15Namespace);
}
try
{
isOptional = XmlUtil.IsTrue(optionalAttribute);
}
catch ( Exception e )
{
if (Fx.IsFatal(e))
throw;
if (e is NullReferenceException)
throw;
importer.Errors.Add(new MetadataConversionError(SR.GetString(SR.UnsupportedBooleanAttribute, OptionalName, e.Message), false));
return false;
}
assertions.RemoveAt(0);
}
}
return (parameters != null);
}
示例12: DeleteParameter
public void DeleteParameter(String parametername)
{
Parameterlist = Read();
int index = 0;
for (int i = 0; i < Parameterlist.Count; i++)
{
if (Parameterlist[i].Name == parametername)
index = i;
}
Parameter.Name = parametername;
Parameterlist.RemoveAt(index);
Create();
Parameterlist.Clear();
Parameterlist = Read();
}
示例13: SaveProject
/// <summary>Saves the project.</summary>
/// <param name="export">Export the sui/sua files, <c>False</c> otherwise.</param>
internal static void SaveProject(bool export = false)
{
var appUpdates = new Collection<Update>();
string appName = Utilities.GetLocaleString(AppInfo.Name);
if (Projects == null)
{
Projects = new Collection<Project>();
}
if (AppInfo.Platform == Platform.X64)
{
if (!appName.Contains("x64") && !appName.Contains("X64"))
{
appName += " (x64)";
}
}
string suiFile = Path.Combine(App.UserStore, appName + ".sui");
string suaFile = Path.Combine(App.UserStore, appName + ".sua");
var updateNames = new ObservableCollection<string>();
string suiFileName = appName;
string suaFileName = appName;
// If SUA exists lets remove the old info
if (AppIndex > -1)
{
if (File.Exists(Path.Combine(App.UserStore, Projects[AppIndex].ApplicationName + ".sui")))
{
appUpdates =
Utilities.Deserialize<Collection<Update>>(
Path.Combine(App.UserStore, Projects[AppIndex].ApplicationName + ".sui"));
}
suiFileName = Projects[AppIndex].ExportedSuiFileName;
suaFileName = Projects[AppIndex].ExportedSuaFileName;
updateNames = Projects[AppIndex].UpdateNames;
Projects.RemoveAt(AppIndex);
}
// If we are just updating the SUA, lets add it
if (appUpdates.Count == 0 || UpdateIndex == -1)
{
updateNames.Add(Utilities.GetLocaleString(UpdateInfo.Name));
appUpdates.Add(UpdateInfo);
}
else
{
// If we are updating the update, lets remove the old info and add the new.
updateNames.RemoveAt(UpdateIndex);
appUpdates.RemoveAt(UpdateIndex);
appUpdates.Add(UpdateInfo);
updateNames.Add(Utilities.GetLocaleString(UpdateInfo.Name));
}
// Save the SUI File
Utilities.Serialize(appUpdates, suiFile);
// Save project file
var project = new Project { ApplicationName = appName, };
foreach (string t in updateNames)
{
project.UpdateNames.Add(t);
}
if (IsNewProject)
{
// Save the SUA file
Utilities.Serialize(AppInfo, suaFile);
}
if (!export)
{
Projects.Insert(0, project);
Utilities.Serialize(Projects, ProjectsFile);
IsNewProject = false;
return;
}
project.ExportedSuiFileName = suiFileName ?? appName;
string fileName = SaveFileDialog(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
project.ExportedSuiFileName,
@"sui");
if (fileName == null)
{
Projects.Insert(0, project);
Utilities.Serialize(Projects, ProjectsFile);
return;
}
project.ExportedSuiFileName = Path.GetFileNameWithoutExtension(fileName);
//.........这里部分代码省略.........
示例14: AreVersionNumberEqual
/// <summary>
/// Verify whether the two version numbers are equal.
/// </summary>
/// <param name="versionsA">A string array indicates the first version number.</param>
/// <param name="versionsB">A string array indicates the second version number.</param>
/// <returns>A Boolean value indicates whether the two version numbers are equal.</returns>
private static bool AreVersionNumberEqual(Collection<string> versionsA, Collection<string> versionsB)
{
foreach (string versionA in versionsA)
{
for (int i = 0; i < versionsB.Count; i++)
{
if (string.Compare(versionA, versionsB[i], true, System.Globalization.CultureInfo.CurrentCulture) == 0)
{
versionsB.RemoveAt(i);
break;
}
}
}
if (versionsB.Count == 0)
{
return true;
}
else
{
return false;
}
}
示例15: ParseNextRecord
//.........这里部分代码省略.........
seenBeginQuote = true;
}
else
{
//We are seeing a quote after the start of
//the word. This is error, however we will be
//lenient here and do what excel does:
//Ex: foo "ba,r"
//In above example word read is ->foo "ba<-
//Basically we read till next delimiter
bool endOfRecord = false;
current.Append(ch);
ReadTillNextDelimiter(current, ref endOfRecord, false);
result.Add(current.ToString());
current.Remove(0, current.Length);
if (endOfRecord)
break;
}
}
else if (ch == ' ' || ch == '\t')
{
if (seenBeginQuote)
{
//Spaces in side quote are valid
current.Append(ch);
}
else if (current.Length == 0)
{
//ignore leading spaces
continue;
}
else
{
//We are not in quote and we are not at the
//beginning of a word. We should not be seeing
//spaces here. This is an error condition, however
//we will be lenient here and do what excel does,
//that is read till next delimiter.
//Ex: ->foo <- is read as ->foo<-
//Ex: ->foo bar<- is read as ->foo bar<-
//Ex: ->foo bar <- is read as ->foo bar <-
//Ex: ->foo bar "er,ror"<- is read as ->foo bar "er<-
bool endOfRecord = false;
current.Append(ch);
ReadTillNextDelimiter(current, ref endOfRecord, true);
result.Add(current.ToString());
current.Remove(0, current.Length);
if (endOfRecord)
break;
}
}
else if (IsNewLine(ch))
{
if (ch == '\r')
{
ReadChar();
}
if (seenBeginQuote)
{
//newline inside quote are valid
current.Append(ch);
if (ch == '\r')
{
current.Append('\n');
}
}
else
{
result.Add(current.ToString());
current.Remove(0, current.Length);
//New line outside quote is end of word and end of record
break;
}
}
else
{
current.Append(ch);
}
}
if (current.Length != 0)
{
result.Add(current.ToString());
}
//Trim all trailing blankspaces and delimiters ( single/multiple ).
// If there is only one element in the row and if its a blankspace we dont trim it.
// A trailing delimiter is represented as a blankspace while being added to result collection
// which is getting trimmed along with blankspaces supplied through the CSV in the below loop.
if (isHeaderRow)
{
while (result.Count > 1 && result[result.Count - 1].Equals(string.Empty))
{
result.RemoveAt(result.Count - 1);
}
}
return result;
}