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


C# SortedList.ContainsKey方法代码示例

本文整理汇总了C#中System.Collections.SortedList.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.ContainsKey方法的具体用法?C# SortedList.ContainsKey怎么用?C# SortedList.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.SortedList的用法示例。


在下文中一共展示了SortedList.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MatchSubstring

        private static Match[] MatchSubstring(string i_source, string i_matchPattern, bool i_uniqueMatch)
        {
            //<note> use RegexOptions.Multiline, otherwise it will treat the whole thing as 1 string
            Regex regex = new Regex(i_matchPattern, RegexOptions.Multiline);

            MatchCollection matchCollection = regex.Matches(i_source);

            Match[] result;
            if (!i_uniqueMatch)
            {
                result = new Match[matchCollection.Count];
                matchCollection.CopyTo(result, 0);
            }
            else
            {
                //<note> cannot use HashSet<Match> because each Match object is unique, even though they may have same value (string). Can use HashSet<string>
                //SortedList is more like sorted Dictionary<key, value>
                SortedList uniqueMatchCollection = new SortedList();
                foreach(Match match in matchCollection)
                {
                    if (!uniqueMatchCollection.ContainsKey(match.Value))
                    {
                        uniqueMatchCollection.Add(match.Value, match);
                    }
                }

                result = new Match[uniqueMatchCollection.Count];
                uniqueMatchCollection.Values.CopyTo(result, 0);     //<note> cannot use uniqueMatchCollection.CopyTo(...) since SortedList member is not type-match with destination array member
            }

            Console.WriteLine("Found {0} matches", result.Length);
            return result;
        }
开发者ID:hsn6,项目名称:csharp_cookbook,代码行数:33,代码来源:EnumerateMatches.cs

示例2: AddNewEntries

        public static AddedAndReplacedEntriesCounter AddNewEntries(SortedList oldKontoEntries, SortedList newEntries)
        {
            var somethingChanged = false;

            var addedEntries = 0;
            var replacedEntries = 0;
            foreach (KontoEntry entry in newEntries.Values) // _newKontoEntries.Values)
            {
                if (!entry.ThisIsDoubleDoNotAdd)
                {
                    if (!oldKontoEntries.ContainsKey(entry.KeyForThis)) // (detta ska redan vara kollat)
                    {
                        if (string.IsNullOrEmpty(entry.ReplaceThisKey)) // Add new
                        {
                            entry.FontFrontColor = Color.Lime;
                            oldKontoEntries.Add(entry.KeyForThis, entry);
                            addedEntries++;
                        }
                        else // Replace old
                        {
                            entry.FontFrontColor = Color.Blue;

                                // ev. skulle man sätta replacethiskey till den gamla keyn med den som ersatte, för att kunna spåra förändringar
                            if (oldKontoEntries.ContainsKey(entry.ReplaceThisKey))
                            {
                                oldKontoEntries[entry.ReplaceThisKey] = entry;
                            }
                            else
                            {
                                MessageBox.Show("Error: key not found! : " + entry.ReplaceThisKey);
                            }

                            replacedEntries++;
                        }

                        somethingChanged = true; // Här har man tagit in nytt som inte är sparat
                    }
                    else
                    {
                        Console.WriteLine("Double key found!: " + entry.KeyForThis);
                    }
                }
            }

            return new AddedAndReplacedEntriesCounter
                   {
                      SomethingChanged = somethingChanged, Added = addedEntries, Replaced = replacedEntries
                   };
        }
开发者ID:perragradeen,项目名称:webbankbudgeter,代码行数:49,代码来源:UiHelpersDependant.cs

示例3: Parse

        public override DialogueAct Parse(SortedList speech, SortedList gesture, Agent agent)
        {
            DialogueAct dlgAct = null;
            // Test for actions
            if (speech.ContainsKey("intention"))
            {
                dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Intend);
                return dlgAct;
            }
            if (this._prevDlgResp != null && this._prevDlgResp.Count > 0)
            {
                // Test for answer to previous questions
                foreach (DialogueResponse resp in this._prevDlgResp)
                {
                    if (resp.DlgRespType == DialogueResponseType.speechQuestion || resp.DlgRespType == DialogueResponseType.listPlainOptions || resp.DlgRespType == DialogueResponseType.listMapLayerOptions || resp.DlgRespType == DialogueResponseType.listOptionsWithExamples)
                    {
                        if (speech.ContainsKey("affirmative"))
                        {
                            dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Accept);
                        }
                        else if (speech.ContainsKey("negative"))
                        {
                            dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Reject);
                        }
                        else
                        {
                            dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Answer); 
                        }
                        return dlgAct;
                    }
                }

                // Test for feedback to previous actions
                foreach (DialogueResponse resp in this._prevDlgResp)
                {
                    if (resp.DlgRespType == DialogueResponseType.drawPolygonStarted)
                    {
                        dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Feedback);
                        return dlgAct;
                    }
                    else if (resp.DlgRespType == DialogueResponseType.selectByAttributes)
                    {
                        dlgAct = new DialogueAct(agent, speech, gesture, DialogueActType.Feedback);
                        return dlgAct;
                    }
                }
            }
            return dlgAct;
        }
开发者ID:cdbean,项目名称:CAGA,代码行数:49,代码来源:SimpleParser.cs

示例4: AddNewEntryFromStringArray

        public static void AddNewEntryFromStringArray(
            BankRow entryStrings,
            SortedList kontoEntries,
            SortedList newKontoEntries,
            SortedList newBatchOfKontoEntriesAlreadyRed)
        {
            var newKeyFromHtml = new KontoEntry(entryStrings);
            var key = newKeyFromHtml.KeyForThis;

            if (!kontoEntries.ContainsKey(key) && !newKontoEntries.ContainsKey(key)) // Kollas även senare
            {
                // if (newKontoEntries != null) {// && !newKontoEntries.ContainsKey(key)) {
                if (key != null)
                {
                    newKontoEntries.Add(key, newKeyFromHtml);

                    // }
                    // else {
                    // //Dubblett
                    // }
                }

                // Handle Doubles
            }
            else if (!newBatchOfKontoEntriesAlreadyRed.ContainsKey(key))
            {
                // Om man hade entryn i Excel, innan laddning, och innan man gick igenom nya, så kan man (förutsätter att man då det inte finns saldo (i allkort-kredit), så läses hela listan in i ett svep, det är inte en lista, det kan ev. bli dubblet om två datum hamnar på olika allkort-kredit-fakturor)
                var userDecision = MessageBox.Show(
                    "Found potential double: " + newKeyFromHtml.KeyForThis,
                    "Double, SaveThisEntry?",
                    MessageBoxButtons.YesNo);

                if (userDecision.Equals(DialogResult.Yes))
                {
                    // Detta är en dubblett, men om det finns fler än 2 dubbletter så måste man se till att nyckeln är unik
                    while (newKontoEntries.ContainsKey(newKeyFromHtml.KeyForThis))
                    {
                        // Stega upp saldo, tills en unik nyckel skapats
                        newKeyFromHtml.SaldoOrginal += newKeyFromHtml.KostnadEllerInkomst != 0
                                                           ? newKeyFromHtml.KostnadEllerInkomst
                                                           : 1;
                    }

                    newKontoEntries.Add(newKeyFromHtml.KeyForThis, newKeyFromHtml);
                }

                // För annat än Allkortskredit, så ordnar Detta sig, så länge saldot är med i nyckeln, det är den, så det gäller bara att ha rätt saldo i xls //Om man tagit utt t.ex. 100kr 2 ggr samma dag, från samma bankomat. hm, sätt 1 etta efteråt, men det göller ju bara det som är såna, hm, får ta dem manuellt
            }
        }
开发者ID:perragradeen,项目名称:webbankbudgeter,代码行数:49,代码来源:EntryAdder.cs

示例5: Main

        static void Main(string[] args)
        {
            if(args.Length == 0)
            {
                Console.WriteLine( "Usage: DumpTypeHashes <assembly> ..." );
                return;
            }

            foreach(string s in args)
            {
                Assembly   assm = Assembly.LoadFrom( s );
                SortedList sl   = new SortedList();

                foreach(Type t in assm.GetTypes())
                {
                    if(sl.ContainsKey( t.FullName ) == false)
                    {
                        sl.Add( t.FullName, Microsoft.SPOT.Debugger.BinaryFormatter.LookupHash( t ) );
                    }
                }

                foreach(string s2 in sl.Keys)
                {
                    Console.WriteLine( "{2} {1:X8} {0}", s2, sl[ s2 ], assm.GetName() );
                }
            }
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:27,代码来源:DumpTypeHashes.cs

示例6: Rank

        public IEnumerable<KeyValuePair<int, double>> Rank(IEnumerable<string> queryTerms, SortedDictionary<string, Term> terms, int documentCount)
        {
            SortedList<int, double> scores = new SortedList<int, double>();
            foreach (var queryTerm in queryTerms)
            {
                if (!terms.ContainsKey(queryTerm))
                    return null;

                Term currentTerm = terms[queryTerm];
                int documentFrequency = currentTerm.Frequency;
                foreach (var posting in currentTerm.Postings)
                {
                    int docId = posting.Key;
                    int termFrequency = posting.Value;
                    double weight = GetTfIdf(termFrequency, documentCount, documentFrequency);
                    if (scores.ContainsKey(docId))
                    {
                        scores[docId] += weight;                        
                    }
                    else
                    {
                        scores.Add(docId, weight);
                    }
                }
            }

            return scores.OrderByDescending(kvp => kvp.Value);
        }
开发者ID:thilemann,项目名称:WebIntelligence,代码行数:28,代码来源:Ranker.cs

示例7: FindSubstrings

        public static Match[] FindSubstrings(string source, string matchPattern, bool findAllUnique)
        {
            SortedList uniqueMatches = new SortedList();
            Match[] retArray = null;

            Regex RE = new Regex(matchPattern, RegexOptions.Multiline);
            MatchCollection theMatches = RE.Matches(source);

            if (findAllUnique)
            {
                for (int counter = 0; counter < theMatches.Count; counter++)
                {
                    if (!uniqueMatches.ContainsKey(theMatches[counter].Value))
                    {
                        uniqueMatches.Add(theMatches[counter].Value,
                                          theMatches[counter]);
                    }
                }

                retArray = new Match[uniqueMatches.Count];
                uniqueMatches.Values.CopyTo(retArray, 0);
            }
            else
            {
                retArray = new Match[theMatches.Count];
                theMatches.CopyTo(retArray, 0);
            }

            return (retArray);
        }
开发者ID:peeboo,项目名称:open-media-library,代码行数:30,代码来源:NetFlixDb.cs

示例8: AddInfo

        private void AddInfo(SortedList<double, ArrayList> timingInfos, TimingInfo newInfo)
        {
            if (!timingInfos.ContainsKey(newInfo.Fps))
            {
                timingInfos.Add(newInfo.Fps, new ArrayList());
            }

            bool found = false;
            foreach (TimingInfo info in timingInfos[newInfo.Fps])
            {
                if (info.T1Value == newInfo.T1Value && info.T2Value == newInfo.T2Value)
                {
                    found = true;
                }
                if (info.T2Value == newInfo.T1Value && info.T1Value == newInfo.T2Value)
                {
                    //found = true;
                }
            }

            if (!found)
            {
                timingInfos[newInfo.Fps].Add(newInfo);
            }
        }
开发者ID:HulaSamsquanch,项目名称:1100d_lantern,代码行数:25,代码来源:TimerGenForm.cs

示例9: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";
            int pageId;

            XmlNode root = _xd.CreateElement("tasks");

            if (int.TryParse(Request["id"], out pageId))
            {
                var t = new Task(pageId);
                if (t.User.Id == base.getUser().Id || t.ParentUser.Id == base.getUser().Id)
                {
                    XmlNode x = CreateTaskNode(t, _xd);
                    root.AppendChild(x);

                    xmlContents.Text = root.OuterXml;

                    Response.AddHeader("Content-Disposition", "attachment; filename=" + t.Node.Text.Replace(" ", "_") + ".xml");
                }
            }
            else
            {
                var nodes = new SortedList();
                int totalWords = 0;

                foreach (Task t in Task.GetTasks(base.getUser(), false))
                {
                    if (!nodes.ContainsKey(t.Node.Path))
                    {
                        var xTask = CreateTaskNode(t, _xd);
                        totalWords += int.Parse(xTask.Attributes.GetNamedItem("TotalWords").Value);
                        nodes.Add(t.Node.Path, xTask);
                    }
                }

                // Arrange nodes in tree
                var ide = nodes.GetEnumerator();
                while (ide.MoveNext())
                {
                    var x = (XmlElement)ide.Value;
                    var parentXpath = UmbracoSettings.UseLegacyXmlSchema ? "//node [@id = '" + x.SelectSingleNode("//node").Attributes.GetNamedItem("parentID").Value + "']" :
                        "//* [@isDoc and @id = '" + x.SelectSingleNode("//* [@isDoc]").Attributes.GetNamedItem("parentID").Value + "']";
                    var parent = _xd.SelectSingleNode(parentXpath);

                    if (parent == null)
                        parent = root;
                    else
                        parent = parent.ParentNode;

                    parent.AppendChild((XmlElement)ide.Value);
                }

                root.Attributes.Append(XmlHelper.AddAttribute(_xd, "TotalWords", totalWords.ToString()));
                xmlContents.Text = root.OuterXml;
                Response.AddHeader("Content-Disposition", "attachment; filename=all.xml");

            }
        }
开发者ID:saciervo,项目名称:Umbraco-CMS,代码行数:58,代码来源:xml.aspx.cs

示例10: Transform

        public virtual System.Data.DataTable Transform(DataTable sourceTable)
        {
            DataTable retTable = sourceTable.Clone(); // only clones the structure

            SortedList<string, string> transposeNames = new SortedList<string, string>();

            PrepareColumns(sourceTable, retTable, transposeNames);

            SortedList<string, DataRow> keyRows = new SortedList<string, DataRow>();

            for (int i = 0; i < sourceTable.Rows.Count; i++)
            {
                DataRow sourceRow = sourceTable.Rows[i];

                // PrepareTransposeKeyKeyColumns(sourceTable, retTable, transposeNames);

                // Null values are normalized to be an empty string

                string trKeyName = String.Empty; 
                object sourceNameObject = sourceRow[transposeDefinition.SourceNameColumnName];

                if (sourceNameObject != null)
                {
                    trKeyName = sourceNameObject.ToString();
                }

                string dataKeyName = String.Empty;
                object dataKeyNameObject = sourceRow[transposeDefinition.KeyColumnName];
                
                if (dataKeyNameObject != null)
                {
                    dataKeyName = dataKeyNameObject.ToString();
                }

                //**

                if (!keyRows.ContainsKey(dataKeyName))
                {
                    DataRow dr = retTable.NewRow();

                    keyRows.Add(dataKeyName, dr);

                    retTable.Rows.Add(dr);

                    FillRow(sourceTable, sourceRow, dr, trKeyName);
                }
                else
                {
                    FillRow(sourceTable, sourceRow, keyRows[dataKeyName], trKeyName);
                }
            }

            ReshuffleColumns(retTable, transposeNames);

            return retTable;


        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:58,代码来源:TransposeDataTableTransformer.cs

示例11: Main

        /// <summary>
        /// The main entry point of the application - does all the work, really.
        /// </summary>
        public static void Main()
        {
            SortedList table = new SortedList();
            string fileData = string.Empty;

            Console.WriteLine("This program counts how many times each word occurs in a file.");
            Console.Write("Enter the filename of the file to read from:\n > ");
            string filename = Console.ReadLine();
            while (string.IsNullOrEmpty(filename))
            {
                Console.Write("You cannot enter a blank path name - try again:\n > ");
                filename = Console.ReadLine();
            }

            // Try to access the file and bail out if an error occurred
            try
            {
                fileData = File.ReadAllText(filename);
            }
            catch
            {
                Console.WriteLine("File was not accessible. Please make sure it exists and you have appropriate permission to read it.");
                return;
            }

            // Get the file contents, convert to lowercase and remove all non-alpha and non-space characters,
            // then get a raw array (still contains duplicates) of all the words
            string[] rawWordArray = WordCountExampleProgram.GetWordsArray(fileData.ToLower());

            // For each for in the array...
            for (int i = 0; i < rawWordArray.Length; i++)
            {
                if (!table.ContainsKey(rawWordArray[i]))
                {
                    // If the table does not already contain the key, add it to the list with a count of 1
                    table.Add(rawWordArray[i], 1);
                }
                else
                {
                    // Otherwise it was already in the table, increment its previous count by one
                    table[rawWordArray[i]] = Convert.ToInt32(table[rawWordArray[i]]) + 1;
                }
            }

            // Make a variable to count total words
            int totalWords = 0;

            // Print out the key and value of each along with some headers
            Console.WriteLine("\nWord" + string.Empty.PadRight(50 - "Word".Length, ' ') + "Count\n" + string.Empty.PadRight(50 + "Count".Length, '-'));
            for (int i = 0; i < table.Count; i++)
            {
                int value = Convert.ToInt32(table.GetByIndex(i));
                totalWords += value;
                Console.WriteLine(String.Format("{0,-50}{1}", table.GetKey(i), value));
            }

            Console.WriteLine("{0,-50}{1}\n", "TOTAL", totalWords);
        }
开发者ID:jakepetroules,项目名称:epgy-archive,代码行数:61,代码来源:WordCountExampleProgram.cs

示例12: GetFunctionsAndAggregates

	    public string GetFunctionsAndAggregates()
		{
			SortedList sortedList = new SortedList(_aggregateNames.Count + _functionNames.Count);
			
			foreach (string key in _aggregateNames.Keys)
			{
				if (!sortedList.ContainsKey(key))
					sortedList.Add(key, null);
			}

			foreach (string key in _functionNames.Keys)
			{
				if (!sortedList.ContainsKey(key))
					sortedList.Add(key, null);
			}
			
			return GetKeys(sortedList);
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:18,代码来源:ScopeInfo.cs

示例13: AnalyzeModifications

		/// <summary>
		/// Build the Modification list of what files will be built 
		/// with this Release
		/// </summary>
		/// <param name="mods"></param>
		/// <returns></returns>
		public static Modification[] AnalyzeModifications(IList mods)
		{
			// Hashtables are used so we can compare on the keys in search of duplicates
			SortedList allFiles = new SortedList();
			foreach (Modification mod in mods)
			{
				string key = mod.FolderName + mod.FileName;
				if (!allFiles.ContainsKey(key))
					allFiles.Add(key, mod);
				else
				{
					// If the revision number on the original is larger, then
					// do the comparision against the original modification
					// in search to see which revision is higher
					// example: 1.64.1 < 1.65 but you need to compare against the 
					// larger string of 1.64.1 because we are splitting the numbers individually
					// so 1 is compared to 1 and 64 is compared to 65.
					Modification compareMod = allFiles[key] as Modification;
					string[] originalVersion = compareMod.Version.Split(char.Parse("."));
					string[] currentVersion = mod.Version.Split(char.Parse("."));
					int len1 = originalVersion.Length;
					int len2 = currentVersion.Length;
					int usingLen;
					int otherLen;
					if (len1 >= len2)
					{
						usingLen = len1;
						otherLen = len2;
					}
					else
					{
						usingLen = len2;
						otherLen = len1;
					}

					for (int i = 0; i < usingLen; i++)
					{
						if (i > otherLen)
							continue;
						if (Convert.ToInt32(currentVersion[i], CultureInfo.CurrentCulture) > Convert.ToInt32(originalVersion[i], CultureInfo.CurrentCulture))
						{
							allFiles[compareMod.FolderName + compareMod.FileName] = mod;
							break;
						}
					}
				}
			}
			// Convert the Hashtables to Modification arrays
			Modification[] validMods = new Modification[allFiles.Count];
			int count = 0;
			foreach (string key in allFiles.Keys)
			{
				validMods[count++] = allFiles[key] as Modification;
			}
			return validMods;
		}
开发者ID:BiYiTuan,项目名称:CruiseControl.NET,代码行数:62,代码来源:PvcsHistoryParser.cs

示例14: BuildTableCellEdgesArray

        /**
     * Creates array of all possible cell edges. In HTML (and FO) cells from
     * different rows and same column should have same width, otherwise spanning
     * shall be used.
     * 
     * @param table
     *            table to build cell edges array from
     * @return array of cell edges (including leftest one) in twips
     */
        public static int[] BuildTableCellEdgesArray(Table table)
        {
            SortedList<int, int> edges = new SortedList<int, int>();

            for (int r = 0; r < table.NumRows; r++)
            {
                TableRow tableRow = table.GetRow(r);
                for (int c = 0; c < tableRow.NumCells(); c++)
                {
                    TableCell tableCell = tableRow.GetCell(c);
                    if (!edges.ContainsKey(tableCell.GetLeftEdge()))
                        edges.Add(tableCell.GetLeftEdge(), 0);
                    if (!edges.ContainsKey(tableCell.GetLeftEdge() + tableCell.GetWidth()))
                        edges.Add(tableCell.GetLeftEdge() + tableCell.GetWidth(), 0);
                }
            }

            int[] result = new int[edges.Count];

            edges.Keys.CopyTo(result, 0);
            return result;
        }
开发者ID:89sos98,项目名称:npoi,代码行数:31,代码来源:AbstractWordUtils.cs

示例15: GetNewBatchOfKontoEntriesAlreadyRed

        public static SortedList GetNewBatchOfKontoEntriesAlreadyRed(
            SortedList kontoEntries, SortedList newKontoEntries)
        {
            var newBatchOfKontoEntriesAlreadyRed = new SortedList();
            foreach (DictionaryEntry entry in newKontoEntries)
            {
                if (!newBatchOfKontoEntriesAlreadyRed.ContainsKey(entry.Key))
                {
                    newBatchOfKontoEntriesAlreadyRed.Add(entry.Key, entry.Value);
                }
            }

            foreach (DictionaryEntry entry in kontoEntries)
            {
                if (!newBatchOfKontoEntriesAlreadyRed.ContainsKey(entry.Key))
                {
                    newBatchOfKontoEntriesAlreadyRed.Add(entry.Key, entry.Value);
                }
            }

            return newBatchOfKontoEntriesAlreadyRed;
        }
开发者ID:perragradeen,项目名称:webbankbudgeter,代码行数:22,代码来源:EntryAdder.cs


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