System.Windows.Forms.Menu.MenuItemCollection.IndexOfKey C# (CSharp) Method

IndexOfKey() public method

public IndexOfKey ( string key ) : int
key string
return int
			public virtual int IndexOfKey (string key)
			{
				if (string.IsNullOrEmpty (key))
					return -1;
					
				return IndexOf (this[key]);
			}

Usage Example

Example #1
0
        public void MenuItemCollection_IndexOfKey_Invoke_ReturnsExpected(string key, int expected)
        {
            var menu = new SubMenu(new MenuItem[] { new MenuItem {
                                                        Name = "name"
                                                    } });
            var collection = new Menu.MenuItemCollection(menu);

            Assert.Equal(expected, collection.IndexOfKey(key));

            // Call again to validate caching behaviour.
            Assert.Equal(expected, collection.IndexOfKey(key));
            Assert.Equal(-1, collection.IndexOfKey("noSuchKey"));
        }