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


C# Dictionary.ElementAt方法代码示例

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


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

示例1: Main

    static void Main()
    { 
        Dictionary<byte, byte> studentHeight = new Dictionary<byte, byte>();
        int n = int.Parse(Console.ReadLine());

        string numbers = Console.ReadLine(); // We have sequence of numbers on one line
        string[] tokens = numbers.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        for (int i = 0; i < n; i++)
        {
            byte height = byte.Parse(tokens[i]);

            if (!studentHeight.ContainsKey(height))
                studentHeight.Add(height, 1);
            else
                studentHeight[height]++;
        }

        int combinations = 0;
        for (int i = 0; i < studentHeight.Count; i++)
        {
            if (studentHeight.ElementAt(i).Value > 1)
            {
                combinations += (int)CalculateCombinations(studentHeight.ElementAt(i).Value);
            }
        }
        Console.WriteLine(combinations);
    }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:28,代码来源:1.+Equal+numbers.cs

示例2: GetShortestLevenshtein

        public static Dictionary<string, int> GetShortestLevenshtein(string givenWord, List<string> words)
        {
            Dictionary<string, int> dists = new Dictionary<string, int>();

            foreach (string word in words) {
                dists.Add(word, LevenshteinDistance(givenWord, word));
            }

            dists = dists.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            var shortestElement = dists.ElementAt(1);
            int shortestDist = shortestElement.Value;

            for (int i = dists.Count - 1; i > 0; i--) {
                var item = dists.ElementAt(i);

                if (item.Value != shortestDist) {
                    dists.Remove(item.Key);
                }
            }

            /* Remove givenWord from the output */
            dists.Remove(dists.ElementAt(0).Key);

            return dists;
        }
开发者ID:ucabpa3,项目名称:WordCloud,代码行数:26,代码来源:EditDistance.cs

示例3: MenuOptions

        public MenuOptions(string title, Dictionary<string, Action<MenuOptionAction>> optionsToActions, int backActionOptionIndex)
        {
            if (backActionOptionIndex >= optionsToActions.Count || backActionOptionIndex < 0)
                throw new ArgumentOutOfRangeException("backActionOptionIndex", "The back action index must be between 0 and the size of the options array");

            finalize(title, optionsToActions, optionsToActions.ElementAt(backActionOptionIndex).Key, optionsToActions.ElementAt(backActionOptionIndex).Value);
        }
开发者ID:foolmoron,项目名称:Retroverse,代码行数:7,代码来源:MenuOptions.cs

示例4: Main

        static void Main(string[] args)
        {
            Dictionary<int, int> deck = new Dictionary<int, int>()
            {
                {2, 0}, {3, 0},
                {4, 0}, {5, 0}, {6, 0},
                {7, 0}, {8, 0}, {9, 0}, {10, 0},
                {11, 0}, {12, 0}, {13, 0}, {14, 0}

            };

            Random rand = new Random();

            for (int i = 0; i < 5; i++)
            {
            Another:
                int rnd = rand.Next(2, 14);
                int currentValue = deck.ElementAt(rnd).Value + 1;
                if((deck.ElementAt(rnd).Value > 4))
                {
                    goto Another;
                } else
                {
                    deck[rnd]++;
                }
            }

            foreach (var item in deck.Where(x => x.Value > 0))
            {

            }
        }
开发者ID:YoungKingRS,项目名称:C-Sharp,代码行数:32,代码来源:Program.cs

示例5: Execute

        public override Exceptional Execute(AGraphDSSharp myAGraphDSSharp, ref String myCurrentPath, Dictionary<String, List<AbstractCLIOption>> myOptions, String myInputString)
        {
            if (myAGraphDSSharp == null)
                return new Exceptional(new GraphDSError("myAGraphDSSharp must not be null!"));

            var _Content        = myOptions.ElementAt(1).Value[0].Option;
            var _FileLocation   = new ObjectLocation(ObjectLocation.ParseString(myCurrentPath), myOptions.ElementAt(2).Value[0].Option);

            if (myAGraphDSSharp.ObjectExists(_FileLocation).Value != Trinary.TRUE)
            {

                try
                {
                    AFSObject _FileObject = new FileObject() { ObjectLocation = _FileLocation, ObjectData = Encoding.UTF8.GetBytes(_Content)};
                    myAGraphDSSharp.StoreFSObject(_FileObject, true);
                }
                catch (Exception e)
                {
                    WriteLine(e.Message);
                }

            }

            else
            {

                if (myAGraphDSSharp.ObjectStreamExists(_FileLocation, FSConstants.INLINEDATA).Value)
                {

                }

            }

            return Exceptional.OK;
        }
开发者ID:TheByte,项目名称:sones,代码行数:35,代码来源:FSCLI_ECHO.cs

示例6: activeSongList

    public void activeSongList(string pack)
    {
        packSelected = pack;
        songList = LoadManager.Instance.ListSong()[pack];
        startnumber = 0;
        currentstartnumber = 0;
        camerasong.transform.position = posBaseCameraSong;

        for(int i=0; i < songList.Count; i++)
        {
            var key = songCubePack.ElementAt(i).Key;
            if(!key.activeInHierarchy)
            {
                key.SetActive(i <= numberToDisplay);
            }
            var songChecked = songList.ElementAt(i).Value.First().Value;
            songCubePack[key] = songChecked.title + ";" + songChecked.subtitle + ";" + songList.ElementAt(i).Key;
            if(packLocked == packSelected && gs.songSelected != null && ((gs.songSelected.First().Value.title + ";" + gs.songSelected.First().Value.subtitle) == (songChecked.title + ";" + songChecked.subtitle)))
            {
                key.transform.FindChild("Selection").gameObject.SetActive(true);
            }else
            {
                key.transform.FindChild("Selection").gameObject.SetActive(false);

            }
        }
        for(int i=songList.Count; i < songCubePack.Count; i++)
        {
            var key = songCubePack.ElementAt(i).Key;
            if(key.activeInHierarchy) key.SetActive(false);
            songCubePack[key] = "";
        }
    }
开发者ID:BenouKat,项目名称:Unity-ITGHD,代码行数:33,代码来源:SongZone.cs

示例7: CreateTypeActions

        public void CreateTypeActions(string actionsmoid, string typeid, string typeidname)
        {
            Dictionary<string, string> StageActions = new Dictionary<string, string>();
            StageActions.Add("Assign Task", "cm.task__create.form");
            StageActions.Add("Send Message", "cm.sendmessage.form");
            StageActions.Add("Log Conversation", "cm.logconversation.form");
            StageActions.Add("Attach Document", "cm.logconversation.form");
            StageActions.Add("Edit Priority", "cm.logconversation.form");

            for (int i = 0; i < StageActions.Count; i++)
            {
                SourceCode.SmartObjects.Client.SmartObject smoTypAction = Client.GetSmartObject(new Guid(actionsmoid));

                smoTypAction.Properties["Name"].Value = StageActions.ElementAt(i).Key;
                smoTypAction.Properties["Description"].Value = StageActions.ElementAt(i).Key;
                smoTypAction.Properties["Sort_Order"].Value = StageActions.ElementAt(i).Key;
                smoTypAction.Properties["Action_Form"].Value = StageActions.ElementAt(i).Value;
                smoTypAction.Properties["Is_Important"].Value = "false";
                smoTypAction.Properties["Created_On"].Value = DateTime.Now.ToString();
                smoTypAction.Properties["Created_By"].Value = "denallix\\administrator";
                smoTypAction.Properties["Modified_On"].Value = DateTime.Now.ToString();
                smoTypAction.Properties["Modified_By"].Value = "denallix\\administrator";
                smoTypAction.Properties["Is_Active"].Value = "true";
                smoTypAction.Properties["Is_Deleted"].Value = "false";
                smoTypAction.Properties["Sort_Order"].Value = i.ToString();

                smoTypAction.Properties[typeidname].Value = typeid;

                smoTypAction.MethodToExecute = "Create";

                SourceCode.SmartObjects.Client.SmartObject result = Client.ExecuteScalar(smoTypAction);
            }
        }
开发者ID:jonnoking,项目名称:K2-Field-App-Framework,代码行数:33,代码来源:MainWindow.xaml.cs

示例8: Post

        public static async Task<string> Post(Uri url, Dictionary<string, string> keyValue)
        {
            try
            {
                using (var client = new HttpClient(
                    new HttpClientHandler
                    {
                        AutomaticDecompression = DecompressionMethods.GZip
                                                 | DecompressionMethods.Deflate
                    }))
                {
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");

                    var arr = new KeyValuePair<string, string>[keyValue.Count];
                    for (int i = 0; i < keyValue.Count; i++)
                    {
                        arr[i] = new KeyValuePair<string, string>(keyValue.ElementAt(i).Key, keyValue.ElementAt(i).Value);
                    }

                    var credentials = new FormUrlEncodedContent(arr);

                    var res = await client.PostAsync(url, credentials);
                    return await res.Content.ReadAsStringAsync();

                }
            }
            catch (Exception ex)
            {

            }
            return null;
        }
开发者ID:famoser,项目名称:UPCConnector,代码行数:32,代码来源:InternetAccessHelper.cs

示例9: GetAllFRItemFromNASDAQ

        //To get all items by running this on all tickers.
        public static void GetAllFRItemFromNASDAQ(string[] tickers, string reportType)
        {
            string periodType = "Annual";
            string numPeriods = "10";
            string reportParam = FinancialReportsConfig.params_NASDAQ[reportType];
            string periodParam = FinancialReportsConfig.params_NASDAQ[periodType];
            var keys = (Dictionary<string, int>)FinancialReportsConfig.mappings_NASDAQ[reportType];

            List<string[]> list = new List<string[]>();
            list.Add(new string[] { "ticker", "not in key", "previous key", "next key", "number" });
            foreach (string ticker in tickers)
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                try
                {
                    WebData webData = new WebData(string.Format(Constants.NASDAQFinancialReportingURL, reportParam, periodParam, numPeriods, ticker));
                    data = webData.ReadNASDAQFRHtmlTable().ElementAt(1);
                }
                catch
                {
                }
                data.Each((d, i) =>
                {
                    int nexti = i + 1 == data.Count ? i : i + 1;
                    if (!keys.ContainsKey(d.Key))
                        list.Add(new string[] { ticker, d.Key, data.ElementAt(i - 1).Key, data.ElementAt(nexti).Key, i.ToString() });
                }
                );

                //list.Add(new string[]{"","","","",""});
            }

            Excel.Worksheet ws = ExcelUtil.Worksheet("Test_" + reportType);
            ws.Range("A2").Resize(list.Count, list[0].Length).Formula = ExcelUtil.To2DArray(list);
        }
开发者ID:chenyuzhcy,项目名称:stock-analysis-addin,代码行数:36,代码来源:FinanceDataLoader.cs

示例10: update

        internal void update(Dictionary<string, string> dictionary)
        {
            //Lock for enumeration thread safety
            lock (slidegen.cstlist)
            {
                if (dictionary != null)
                {
                    for (int i = 0; i < dictionary.Count; i++)
                    {
                        if (slidegen.cstlist.ContainsKey(dictionary.ElementAt(i).Key))
                        {
                            slidegen.cstlist[dictionary.ElementAt(i).Key] = dictionary.ElementAt(i).Value;
                            if(dictionary.ElementAt(i).Key =="CURRENTARTIST")
                                slidegen.cstlist["ARTIST"] = dictionary.ElementAt(i).Value;
                            if (dictionary.ElementAt(i).Key == "CURRENTTITLE")
                                slidegen.cstlist["TITLE"] = dictionary.ElementAt(i).Value;
                        }
                        else
                        {
                            slidegen.cstlist.Add(dictionary.ElementAt(i).Key, dictionary.ElementAt(i).Value);

                            if (dictionary.ElementAt(i).Key == "CURRENTARTIST")
                                slidegen.cstlist.Add("ARTIST", dictionary.ElementAt(i).Value);
                            if (dictionary.ElementAt(i).Key == "CURRENTTITLE")
                                slidegen.cstlist.Add("TITLE", dictionary.ElementAt(i).Value);
                        }
                    }
                }
            }
        }
开发者ID:kaizadj,项目名称:ebu-radio-production,代码行数:30,代码来源:ContentManagerCore.cs

示例11: Main

        static void Main(string[] args)
        {
            // Write a program that finds the most frequent number in an array.
            // Example: {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3} -> 4 (5 times)

            int[] arr = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };
            Dictionary<int, int> frequencyMeter = new Dictionary<int, int>();

            for (int i = 0; i < arr.Length; i++)
            {
                if (frequencyMeter.ContainsKey(arr[i]))
                {
                    frequencyMeter[arr[i]]++;
                }
                else
                {
                    frequencyMeter.Add(arr[i], 1);
                }
            }

            int maxOccurences = frequencyMeter.ElementAt(0).Value;
            int number = frequencyMeter.ElementAt(0).Key;
            foreach (KeyValuePair<int, int> pair in frequencyMeter)
            {
                if (pair.Value > maxOccurences)
                {
                    maxOccurences = pair.Value;
                    number = pair.Key;
                }
            }

            Console.WriteLine("{0} ({1} times)", number, maxOccurences);
        }
开发者ID:vtsenev,项目名称:CSharpPractice,代码行数:33,代码来源:Program.cs

示例12: MainPage

        public MainPage()
        {
            Game game;
            game = new Game();
            TTskProvider tprov = new TTskProvider(game);
            tprov.tskBad(tprov.encodeTask('f'));
            tprov.tskBad(tprov.encodeTask('g'));
            tprov.tskBad(tprov.encodeTask('g'));
            tprov.tskBad(tprov.encodeTask('g'));
            tprov.tskBad(tprov.encodeTask('h'));

            tprov.tskGood(tprov.encodeTask('h'),true);

            TRandom rand = new TRandom("0123456789", null,0);
            Dictionary<Char, int> dic = new Dictionary<Char, int>();
            rand.count = 6;
            rand.only.Add(2);
            rand.only.Add(1);
            rand.only.Add(5);

            rand.freq[2] = 1;
            rand.freq[4] = 2;
            Char c;
            String res = "";
            string res1 = "";
            for (int i = 0; i < rand.count; i++) dic.Add(rand.charAt(i), 0);
            for (int i = 0; i < 800; i++) { res += (c = rand.getVal()); dic[c]++; }
            for (int i = 0; i < dic.Count; i++)res1 += " " + dic.ElementAt(i).Key + '='+dic.ElementAt(i).Value.ToString() + ' ';
            InitializeComponent();
        }
开发者ID:prog76,项目名称:Pacman,代码行数:30,代码来源:MainPage.xaml.cs

示例13: PlayCutscene

 public IEnumerator PlayCutscene(Dictionary<Transform, Vector3> _ship_gridPos_Table)
 {
     this.ship_gridPos_Table = _ship_gridPos_Table;
     yield return StartCoroutine(PreCutscene());
     foreach (var ship_gridPos in ship_gridPos_Table)
     {
         Transform shipTrans = ship_gridPos.Key;
         int hangarIndex = Random.Range(0, hangars.Length);
         shipTrans.position = hangars[hangarIndex].position;
         shipTrans.rotation = hangars[hangarIndex].rotation;
     }
     for (int i = 0; i < ship_gridPos_Table.Count; i++)
     {
         if (skipCutscene) yield break;
         Transform shipTrans = ship_gridPos_Table.ElementAt(i).Key;
         Vector3 destination = ship_gridPos_Table.ElementAt(i).Value;
         yield return StartCoroutine(ExitHangar(shipTrans));
         if (skipCutscene) yield break;
         yield return StartCoroutine(FlyToGridPos(shipTrans, destination));
         if (skipCutscene) yield break;
         //swing back to mothership until last ship
         if (!skipCutscene && i < ship_gridPos_Table.Count - 1)
         {
             yield return StartCoroutine(CameraDirector.Instance.MoveAndRotate(camMotherShipPos, camMotherShipRot, 1.0f));
         }
         shipTrans.position = destination;
         shipTrans.rotation = Quaternion.identity;
     }
     PostCutscene();
 }
开发者ID:HaKDMoDz,项目名称:Capstone_Space_Game,代码行数:30,代码来源:MothershipLaunchCutscene.cs

示例14: Main

    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("Knapsack Problem Solution :)");
        Console.WriteLine();
        Console.ResetColor();

        // Checking input size of the knapsack.
        string consoleInputKnapsackSize = default(string);
        int knapsackSize = default(int);
        ValidateTheInputKnapsackSize(ref consoleInputKnapsackSize, ref knapsackSize);

        // Checking input count of products.
        string consoleInputProductsCount = default(string);
        int productsCount = default(int);
        ValidateTheInputProductsCount(ref consoleInputProductsCount, ref productsCount);

        Console.WriteLine();
        Console.WriteLine("Example for product adding...");
        Console.WriteLine("beer–3-2 => name=beer – weight=3 - cost=2");
        Console.WriteLine();

        // In this dictionary will be added to all products.
        Dictionary<string, List<int>> allProducts = new Dictionary<string, List<int>>();

        // This for loop will get all inputed products from console.
        GetAllInputedProductsFromConsole(productsCount, allProducts);

        // Verify that only one product is added and return it as a result.
        if (allProducts.Count == 1)
        {
            string firstProductName = allProducts.ElementAt(0).Key;
            int firstProductWeight = allProducts.ElementAt(0).Value[0];
            int firstProductCost = allProducts.ElementAt(0).Value[1];

            Console.WriteLine("Best solution is: Name=" + firstProductName + 
                " - Weight=" + firstProductWeight + " - Cost=" + firstProductCost);

            return;
        }

        // Arrays for dynamic programming solution of the problem.
        int[,] valuesArray = new int[productsCount + 1, knapsackSize + 1];
        int[,] keepArray = new int[productsCount + 1, knapsackSize + 1];

        InputTheProductsDataIntoArrays(allProducts, valuesArray, keepArray);

        List<string> bestSolutionItems = new List<string>();

        FindBestSolutionItems(knapsackSize, allProducts, keepArray, bestSolutionItems);

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine();
        Console.Write("Best choice is: ");
        Console.WriteLine(string.Join(", ", bestSolutionItems));
        Console.ResetColor();

        Console.ReadLine();
    }
开发者ID:BorislavIvanov,项目名称:Telerik_Academy,代码行数:59,代码来源:KnapsackProblemSolution.cs

示例15: OnTick

        public void OnTick(object sender, EventArgs e)
        {
            if (!Main.IsOnServer()) return;

            const int npcThreshold = 5000; // 5 second timeout
            const int playerThreshold = 60000; // 60 second timeout

            Dictionary<long, SyncPed> localOpps = null;
            lock (Main.Opponents) localOpps = new Dictionary<long, SyncPed>(Main.Opponents);
            for (int i = localOpps.Count - 1; i >= 0; i--)
            {
                if (DateTime.Now.Subtract(localOpps.ElementAt(i).Value.LastUpdateReceived).TotalMilliseconds > playerThreshold)
                {
                    var key = localOpps.ElementAt(i).Key;
                    localOpps[key].Clear();
                    localOpps.Remove(key);
                }
            }

            Dictionary<string, SyncPed> localNpcs = null;
            lock (Main.Npcs) localNpcs = new Dictionary<string, SyncPed>(Main.Npcs);
            for (int i = localNpcs.Count - 1; i >= 0; i--)
            {
                if (DateTime.Now.Subtract(localNpcs.ElementAt(i).Value.LastUpdateReceived).TotalMilliseconds > npcThreshold)
                {
                    var key = localNpcs.ElementAt(i).Key;
                    localNpcs[key].Clear();
                    localNpcs.Remove(key);
                }
            }

            lock (Main.Opponents) foreach (KeyValuePair<long, SyncPed> opp in new Dictionary<long, SyncPed>(Main.Opponents)) if (!localOpps.ContainsKey(opp.Key)) Main.Opponents.Remove(opp.Key);

            lock (Main.Npcs) foreach (KeyValuePair<string, SyncPed> npc in new Dictionary<string, SyncPed>(Main.Npcs)) if (!localNpcs.ContainsKey(npc.Key)) Main.Npcs.Remove(npc.Key);

            for (int i = 0; i < localOpps.Count; i++) localOpps.ElementAt(i).Value.DisplayLocally();

            for (int i = 0; i < localNpcs.Count; i++) localNpcs.ElementAt(i).Value.DisplayLocally();

            if (Main.SendNpcs)
            {
                var list = new List<int>(localNpcs.Where(pair => pair.Value.Character != null).Select(pair => pair.Value.Character.Handle));
                list.AddRange(localOpps.Where(pair => pair.Value.Character != null).Select(pair => pair.Value.Character.Handle));
                list.Add(Game.Player.Character.Handle);

                foreach (Ped ped in World.GetAllPeds()
                    .OrderBy(p => (p.Position - Game.Player.Character.Position).Length())
                    .Take(Main.PlayerSettings.MaxStreamedNpcs == 0 ? 10 : Main.PlayerSettings.MaxStreamedNpcs))
                {
                    if (!list.Contains(ped.Handle))
                    {
                        Main.SendPedData(ped);
                    }
                }
            }

            Main.SendPlayerData();
        }
开发者ID:butich,项目名称:GTACoop,代码行数:58,代码来源:PedThread.cs


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