当前位置: 首页>>代码示例>>C#>>正文


C# Collection.Contains方法代码示例

本文整理汇总了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;
 }
开发者ID:nickchal,项目名称:pash,代码行数:29,代码来源:MUIFileSearcher.cs

示例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();
            }
        }
开发者ID:kirlianstudios,项目名称:armada,代码行数:13,代码来源:PcControlScheme.cs

示例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));
        }
开发者ID:ikyaqoob,项目名称:RabbitCache,代码行数:16,代码来源:CollectionExtensionTest.cs

示例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;
        }
开发者ID:BryanCAlcorn,项目名称:Trimmer,代码行数:60,代码来源:Form1.cs

示例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;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:40,代码来源:NuGenContextMenusForm.cs

示例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);
     }
 }
开发者ID:ChanahC,项目名称:CSharpTrain,代码行数:25,代码来源:CollectionTrial.cs

示例7: AddError

 public static void AddError(ImportErrorCode error, Collection<ImportErrorCode> errorCode)
 {
     if ((error != ImportErrorCode.Ok) && (!errorCode.Contains(error)))
     {
         errorCode.Add(error);
     }
 }
开发者ID:thaond,项目名称:vdms-sym-project,代码行数:7,代码来源:AutoReceiveVehicle.cs

示例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);
            }
        }
开发者ID:pwibeck,项目名称:InstallerVerificationFramework,代码行数:26,代码来源:DataPropertyTool.cs

示例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);
 }
开发者ID:ryanhorath,项目名称:Rybird.Framework,代码行数:17,代码来源:CollectionSyncerTests.cs

示例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);
        }
开发者ID:francis04j,项目名称:LayeredArchitecture,代码行数:11,代码来源:CollectionExtenderTests.cs

示例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);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:FileSystem.cs

示例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);
            }
        }
开发者ID:paulkearney,项目名称:brnkly,代码行数:13,代码来源:MarkupCleaner.cs

示例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);
        }
开发者ID:kirlianstudios,项目名称:armada,代码行数:14,代码来源:FpsCameraScheme.cs

示例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);
            }
        }
开发者ID:kirlianstudios,项目名称:armada,代码行数:49,代码来源:KeyboardInputDevice.cs

示例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;
 }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:16,代码来源:FormattingUtilities.cs


注:本文中的Collection.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。