本文整理汇总了C#中Collection.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.Contains方法的具体用法?C# Collection.Contains怎么用?C# Collection.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NormalizeSearchPaths
private static Collection<string> NormalizeSearchPaths(string target, Collection<string> searchPaths)
{
Collection<string> collection = new Collection<string>();
if (!string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(Path.GetDirectoryName(target)))
{
string directoryName = Path.GetDirectoryName(target);
if (Directory.Exists(directoryName))
{
collection.Add(Path.GetFullPath(directoryName));
}
return collection;
}
if (searchPaths != null)
{
foreach (string str2 in searchPaths)
{
if (!collection.Contains(str2) && Directory.Exists(str2))
{
collection.Add(str2);
}
}
}
string mshDefaultInstallationPath = GetMshDefaultInstallationPath();
if (((mshDefaultInstallationPath != null) && !collection.Contains(mshDefaultInstallationPath)) && Directory.Exists(mshDefaultInstallationPath))
{
collection.Add(mshDefaultInstallationPath);
}
return collection;
}
示例2: Keyboard_KeyPress
private void Keyboard_KeyPress(Collection<Keys> a_keys)
{
if (a_keys.Contains(Keys.F))
{
Game.ToggleFullScreen();
}
// Allows the game to exit
if (a_keys.Contains(Keys.Escape))
{
Engine.Game.Exit();
}
}
示例3: AddWhenTimoutNotElapsedTest
public void AddWhenTimoutNotElapsedTest()
{
var _objects = new Collection<object>();
var _newObject = new object();
Parallel.Invoke(
() => _objects.Add(_newObject, 50, () => _objects.Remove(_newObject)),
() =>
{
Thread.Sleep(10);
Assert.IsTrue(_objects.Contains(_newObject));
}
);
Assert.IsTrue(_objects.Contains(_newObject));
}
示例4: btnTrimFiles_Click
private void btnTrimFiles_Click(object sender, EventArgs e)
{
Collection<string> fileTypesToTrim = new Collection<string>();
if (cbAspx.Checked)
{
fileTypesToTrim.Add(".aspx");
}
if (cbconfig.Checked)
{
fileTypesToTrim.Add(".config");
}
if (cbCs.Checked)
{
fileTypesToTrim.Add(".cs");
}
if (cbTxt.Checked)
{
fileTypesToTrim.Add(".txt");
}
if (cbXml.Checked)
{
fileTypesToTrim.Add(".xml");
}
string[] inputFileTypes = txtFileTypeInputs.Text.ToLower().Trim().Split(',');
foreach (string type in inputFileTypes)
{
if (type.StartsWith("."))
{
fileTypesToTrim.Add(type);
}
}
char[] trimmers = { ' ', '\t', '\n' };
SearchOption option = (cbTrimSubFolders.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
string[] allFiles = Directory.GetFiles(lblFolderPath.Text, "*", option);
foreach (string filePath in allFiles)
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists && fileTypesToTrim.Contains(fileInfo.Extension.ToLower()))
{
//Get All lines for the file and trim off spaces and tabs, replace new-line character if it was there.
string[] allLines = File.ReadAllLines(filePath);
for (int i = 0; i < allLines.Length;i++ )
{
if (allLines[i].EndsWith("\n"))
{
allLines[i] = allLines[i].TrimEnd(trimmers) + "\n";
}
else
{
allLines[i] = allLines[i].TrimEnd(trimmers);
}
}
File.WriteAllLines(filePath, allLines);
}
}
lblCompleted.Visible = true;
}
示例5: NuGenContextMenusForm
/// <summary>
/// Initializes a new instance of the <see cref="NuGenContextMenusForm"/> class.
/// </summary>
/// <param name="UISwitchboard">The command switchboard</param>
/// <param name="associatedItems">Context menus associated.</param>
/// <param name="availableItems">Context menus available.</param>
public NuGenContextMenusForm(NuGenCommandManagerBase UISwitchboard, Collection<object> associatedItems, Collection<object> availableItems)
{
this.UISwitchboard = UISwitchboard;
this.associatedItems = associatedItems;
this.availableItems = availableItems;
InitializeComponent();
// Fill listview with associated items
foreach (object item in associatedItems)
{
string name = UISwitchboard.UIItemAdapter.GetContextMenuName(item);
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = name;
listViewItem.Tag = item;
listViewAssociatedItems.Items.Add(listViewItem);
}
// Fill listview with available items
foreach (object item in availableItems)
{
if (!associatedItems.Contains(item))
{
string name = UISwitchboard.UIItemAdapter.GetContextMenuName(item);
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = name;
listViewItem.Tag = item;
listViewAvailableItems.Items.Add(listViewItem);
}
}
columnHeaderAvailableItems.Width = listViewAvailableItems.ClientSize.Width;
columnHeaderAssociatedItems.Width = listViewAssociatedItems.ClientSize.Width;
}
示例6: Main
private static void Main()
{
ICollection<string> myCole = new Collection<string>(); //Initializing a collection of strings
myCole.Add("Takane"); //Adding elements on a collection
myCole.Add("Sena");
myCole.Add("Masuzu");
myCole.Add("Yusa Emi");
foreach(string b in myCole){
Console.WriteLine("myCole contains " + b);
}
myCole.Remove("Yusa Emi"); //removing an element on a collection
Console.WriteLine("Deleted an element");
bool a = myCole.Contains("Takane"); //tells whether the collection contains a certain element
//enumerate the elements
foreach(string b in myCole){
Console.WriteLine("myCole contains " + b);
}
//copying the content of a collection to an array
string[] c = new string[myCole.Count]; // initializes the array with the size equal to myCole
myCole.CopyTo(c, 0); //Copy to string array c from element 0
foreach(string d in c){
Console.WriteLine("String Copy in c: {0}", d);
}
}
示例7: AddError
public static void AddError(ImportErrorCode error, Collection<ImportErrorCode> errorCode)
{
if ((error != ImportErrorCode.Ok) && (!errorCode.Contains(error)))
{
errorCode.Add(error);
}
}
示例8: CheckForMissSpelledPropertyTypes
private static void CheckForMissSpelledPropertyTypes(ICollection<XElement> properties)
{
var allowedTypes = new Collection<string>
{
DataPropertyType.EnvironmentVariable.ToString().ToUpperInvariant(),
DataPropertyType.Text.ToString().ToUpperInvariant(),
DataPropertyType.Parameter.ToString().ToUpperInvariant(),
DataPropertyType.RegistryPathExist.ToString().ToUpperInvariant(),
DataPropertyType.RegistryValue.ToString().ToUpperInvariant(),
DataPropertyType.SpecialFolderPath.ToString().ToUpperInvariant(),
DataPropertyType.WindowsInstaller.ToString().ToUpperInvariant()
};
foreach (var property in properties)
{
var type = XmlTools.GetNamedAttributeValue(property, "type", string.Empty).ToUpperInvariant();
if (allowedTypes.Contains(type))
{
continue;
}
var msg = "Wrong type attribute in Property Node: '" + property.CreateNavigator().OuterXml + "'";
Log.WriteError(msg, "ExtractProperties");
throw new InstallerVerificationLibraryException(msg);
}
}
示例9: TestAddRemoveDispose
public void TestAddRemoveDispose()
{
var sourceList = new ObservableList<string>();
var targetList = new Collection<string>();
var syncer1 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x.ToUpper(), (x) => x.ToUpper(), false);
var syncer2 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x.ToLower(), (x) => x.ToLower(), false);
sourceList.Add("Test1");
Assert.Equal(2, targetList.Count);
Assert.True(targetList.Contains("test1"));
Assert.True(targetList.Contains("TEST1"));
sourceList.Remove("Test1");
Assert.Equal(sourceList.Count, targetList.Count);
Assert.Equal(0, targetList.Count);
syncer2.Dispose();
sourceList.Add("Test1");
Assert.Equal(sourceList.Count, targetList.Count);
}
示例10: AddRange_ICollection_Test
public static void AddRange_ICollection_Test()
{
var collection1 = new Collection<string>();
var collection2 = new LinkedList<string>();
collection2.AddFirst("Hello");
collection1.AddRange(collection2);
Assert.That(collection1.Contains("Hello"), Is.True);
}
示例11: AddToStringCollection
private static void AddToStringCollection(Collection<string> StrCollection, string[] StrArray)
{
if (StrArray != null)
{
foreach (string str in StrArray)
{
if (!StrCollection.Contains(str))
{
StrCollection.Add(str);
}
}
}
}
示例12: RemoveElementsNotInWhitelist
public static void RemoveElementsNotInWhitelist(XElement xml, Collection<string> whitelist)
{
var badTags =
xml.Descendants()
.Where(d => !whitelist.Contains(d.Name.ToString()))
.Select(d => d).ToList();
foreach (var tag in badTags)
{
var nodes = tag.Nodes();
tag.ReplaceWith(nodes);
}
}
示例13: Keyboard_KeyHold
private void Keyboard_KeyHold(Collection<Keys> a_keys)
{
var translation = new Vector3();
foreach (Keys key in Map.Keys)
{
if (a_keys.Contains(key))
{
translation += Map[key];
}
}
ActiveCamera.Translate(translation);
}
示例14: Update
public override void Update(GameTime a_gameTime)
{
var currentState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
var currentPressedKeys = new Collection<Keys>(currentState.GetPressedKeys());
LastPressedKeys = new Collection<Keys>(LastState.GetPressedKeys());
LastState = currentState;
Pressed = new Collection<Keys>();
Held = new Collection<Keys>();
Released = new Collection<Keys>();
// Loading Event Lists
foreach (Keys key in currentPressedKeys)
{
if (LastPressedKeys.Contains(key))
{
Held.Add(key);
}
else
{
Pressed.Add(key);
}
}
foreach (Keys key in LastPressedKeys)
{
if (!currentPressedKeys.Contains(key))
{
Released.Add(key);
}
}
// Event Calls
if (Pressed.Count > 0 && null != KeyPress)
{
KeyPress(Pressed);
}
if (Held.Count > 0 && null != KeyHold)
{
KeyHold(Held);
}
if (Released.Count > 0 && null != KeyRelease)
{
KeyRelease(Released);
}
}
示例15: ValidateCollection
public static bool ValidateCollection(Collection<MediaTypeHeaderValue> actual, MediaTypeHeaderValue[] expected)
{
if (actual.Count != expected.Length)
{
return false;
}
for (int i = 0; i < expected.Length; i++)
{
MediaTypeHeaderValue item = expected[i];
if (!actual.Contains(item))
{
return false;
}
}
return true;
}