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


C# Collection.ElementAt方法代码示例

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


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

示例1: OnNavigatedTo

 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     usus = new Collection<Usuario>();
     usus = e.Parameter as Collection<Usuario>;
     usu = usus.ElementAt<Usuario>(1);
     medico = usus.ElementAt<Usuario>(0);
     llenarDatos();
     Nombre.Text = usu.Nombre + " " + usu.Apellido;
     Correo.Text = usu.Correo;
     Cedula.Text = ""+usu.Cedula;
     Telefono.Text = ""+usu.Telefono;              
 }
开发者ID:davidguzman1693,项目名称:W10TreatSelf,代码行数:12,代码来源:AddPacTra.xaml.cs

示例2: selectTargetsFromBoard

        public Collection<Minion> selectTargetsFromBoard(Board board, Vector3 selectionPoint, int targetCount, float minRange, float maxRange, MinionStateSelection minionState)
        {
            Collection<Minion> minionsInRange = new Collection<Minion>();
            Collection<Minion> minionsUnderAttack = new Collection<Minion>();

            foreach (var v in board.minions)
            {
                if (v.Value.destroyable == true || (minionState != MinionStateSelection.ANY && ((v.Value.minionState == Minion.MinionState.DEAD && minionState == MinionStateSelection.ALIVE)
                     || (v.Value.minionState == Minion.MinionState.ALIVE && minionState == MinionStateSelection.DEAD))))
                    continue;

                Vector3 minionCoor = v.Value.getWorldPosition();
                float dist = (selectionPoint - minionCoor).magnitude;

                if (v.Value.isUntargetable() == false && dist >= minRange && dist <= maxRange)
                    minionsInRange.Add(v.Value);
            }

            if (targetCount >= minionsInRange.Count)
                return minionsInRange;

            for (int i = 0; i < targetCount; i++)
            {
                if (minionsInRange.Count > 0)
                {
                    float current = float.MinValue;
                    int index = -1;

                    for (int j = 0; j < minionsInRange.Count; j++)
                    {
                        Vector3 minionCoor = minionsInRange.ElementAt(j).getWorldPosition();
                        float dist = (selectionPoint - minionCoor).magnitude;
                        if (dist > current)
                        {
                            index = j;
                            current = dist;
                        }
                    }

                    if (index != -1)
                    {
                        minionsUnderAttack.Add(minionsInRange.ElementAt(index));
                        minionsInRange.RemoveAt(index);
                    }
                }
                else
                    return minionsUnderAttack;
            }

            return minionsUnderAttack;
        }
开发者ID:btasdoven,项目名称:ScienceWars,代码行数:51,代码来源:FarthestMinionTargetStrategy.cs

示例3: FindFile

		static public string FindFile(string filnam, Collection<string> searchPaths, string falseVal) {
			string rv = falseVal;
			
			if (filnam != null) {
				if (filnam.Substring(1, 2) != @":\") {
					if (File.Exists(filnam)) rv = filnam;
				}
				else {
					int cnt=2, i;
					if(searchPaths!=null) cnt+=searchPaths.Count;
					string[] sp=new string[cnt];
					string str;
					
					sp[0]=curDir;
					if (cnt>2)
						for (i = 1; i < (cnt - 2); i++) sp[i] = searchPaths.ElementAt(i - 1);
					sp[cnt-1]=appDir;

					i = 0;
					while(i < cnt) {
						str = Path.Combine(sp[i], filnam);
						if(File.Exists(str)) { i=200000; rv=str; }
						else i++;
					}

				}
				
			}

			return rv;
		}
开发者ID:erin100280,项目名称:Zelda.NET,代码行数:31,代码来源:fs.cs

示例4: see_if_we_get_a_not_disposed_warning

        public void see_if_we_get_a_not_disposed_warning()
        {
            Repository repository = new Repository(_localDirectory_cloned);
            var head = repository.Get<Commit>("HEAD");
            var log = new Collection<Commit>();

            Console.WriteLine(head.Message);
            log.Add(head);
            log.Add(head.Parent);

            for (int i=0; i<log.Count(); i++)
                Console.WriteLine(log.ElementAt(i).Message);

            GitChangesetRepository gcr = new GitChangesetRepository(_localDirectory_cloned);
            var testGet = gcr.Get(new ChangesetsAfterRevisionSpecification(65));
        }
开发者ID:flyrev,项目名称:Smeedee_git_plugin,代码行数:16,代码来源:GitSharpDisposeRepositoryTest.cs

示例5: extendedSearch

        private ObservableCollection<SearchResultFile> extendedSearch(string searchTerm, string oldSearchTerm, Collection<SearchableFile> searchable, Collection<SearchResultFile> preResults)
        {
            if (searchable.Count != preResults.Count)
                return search(searchTerm, allFiles); // default - search everything

            for (int i = 0; i < searchable.Count; i++)
            {
                SearchableFile sf = searchable.ElementAt(i);
                SearchResultFile sr = preResults.ElementAt(i);
                SearchResultFile postResult = new SearchResultFile(sf);

                foreach (KeyValuePair<int, string[]> hit in sr.hits)
                {
                    int index = hit.Key;

                    // filename hit
                    if (index == -1 && sf.FileName.ToLower().Contains(searchTerm.ToLower()))
                    {
                        int index2 = sf.FileName.ToLower().IndexOf(searchTerm.ToLower());
                        string[] surroundingText = new string[3];
                        surroundingText[0] = sf.FileName.Substring(0, index2);
                        surroundingText[1] = sf.FileName.Substring(index2, searchTerm.Length);
                        surroundingText[2] = sf.FileName.Substring(index2 + searchTerm.Length);
                        postResult.AddHit(-1, surroundingText);
                    }

                    int end = Math.Min(searchTerm.Length, sf.FileText.Length - index);
                    if (index > -1 && sf.FileText.Substring(index, end).ToLower().Equals(searchTerm.ToLower()))
                    {
                        string[] surroundingText = new string[3];
                        surroundingText[0] = hit.Value[0];
                        surroundingText[1] = hit.Value[1] + hit.Value[2].Substring(0, searchTerm.Length - oldSearchTerm.Length);
                        surroundingText[2] = hit.Value[2].Substring(searchTerm.Length - oldSearchTerm.Length);
                        postResult.AddHit(index, surroundingText);
                    }
                }
                if (postResult.GetNumHits() > 0)
                {
                    lastSearchResults[searchTerm].Key.Add(sf);
                    lastSearchResults[searchTerm].Value.Add(postResult);
                }
            }
            return new ObservableCollection<SearchResultFile>(lastSearchResults[searchTerm].Value);
        }
开发者ID:hmehart,项目名称:Notepad,代码行数:44,代码来源:Searcher.cs

示例6: ResetTagWidthsToDefault

        public void ResetTagWidthsToDefault()
        {
        	IEnumerable<int> defaultTagWidth = new Collection<int>
	        {
	        	20,
	        	393,
	        	80,
	        	55,
	        	90
        	}.AsEnumerable();
        	
			for (int position = 0, queueTagWidthsCount = queueTagWidths.Count; position < queueTagWidthsCount; position++)
			{
				queueTagWidths[position] = defaultTagWidth.ElementAt(position);
			}
        }
开发者ID:AnonymousUser200102010,项目名称:Youtube-Download-Helper,代码行数:16,代码来源:Custom.cs

示例7: doTimes

 private void doTimes(String results)
 {
     var movieTimes = new Collection<String>();
     var timesResult = JsonUtils.GetItems(results, new String[] { "day", "screenings" });
     foreach (Dictionary<String, String> times in timesResult)
     {
         if (times["day"] != "")
         {
             movieTimes.Add(times["day"] + "\n" + times["screenings"]);
         }
         else if (times["screenings"] != "")
         {
             int last = movieTimes.Count - 1;
             var previousTime = movieTimes.ElementAt(last);
             previousTime += " " + times["screenings"];
             movieTimes.RemoveAt(last);
             movieTimes.Insert(last, previousTime);
         }
         else
         {
             movieTimes.Add("No Showings!");
         }
     }
     Dispatcher.BeginInvoke(() => ShowingsList.ItemsSource = movieTimes);
 }
开发者ID:fluffy88,项目名称:Irish-Cinema-Listings,代码行数:25,代码来源:MoviePage.xaml.cs

示例8: Main

    private static void Main(string[] args)
    {
        string[] inputs;

        // game loop
        while (true)
        {
            var mySelf = new MySelf();
            var human = new Human();
            var humans = new Collection<Human>();
            var zombie = new Zombie();
            var zombies = new Collection<Zombie>();

            inputs = Console.ReadLine().Split(' ');
            mySelf.MyCoordinateX = int.Parse(inputs[0]);
            mySelf.MyCoordinateY = int.Parse(inputs[1]);
            Console.Error.WriteLine("My position: " + mySelf.MyCoordinateX + " " + mySelf.MyCoordinateY);

            int humanCount = int.Parse(Console.ReadLine());
            Console.Error.WriteLine("Humans Alive: " + humanCount);

            for (int i = 0; i < humanCount; i++)
            {
                inputs = Console.ReadLine().Split(' ');

                human.HumanId = int.Parse(inputs[0]);

                human.HumanX = int.Parse(inputs[1]);
                human.HumanY = int.Parse(inputs[2]);

                human.Humans.Add(human);

                Console.Error.WriteLine("Human " + human.HumanId + " is located at: " + human.HumanX + " " +
                                        human.HumanY);
            }

            int zombieCount = int.Parse(Console.ReadLine());
            Console.Error.WriteLine("I have to kill " + zombieCount + " zombies!");

            for (int i = 0; i < zombieCount; i++)
            {
                inputs = Console.ReadLine().Split(' ');

                zombie.ZombieId = int.Parse(inputs[0]);

                zombie.ZombieX = int.Parse(inputs[1]);
                zombie.ZombieY = int.Parse(inputs[2]);

                zombie.ZombieNextX = int.Parse(inputs[3]);
                zombie.ZombieNextY = int.Parse(inputs[4]);

                zombie.Zombies.Add(zombie);

                Console.Error.WriteLine("Zombie " + zombie.ZombieId + " is located at: " + zombie.ZombieX + " " +
                                        zombie.ZombieY);
                Console.Error.WriteLine("Zombie " + zombie.ZombieId + " is going to: " + zombie.ZombieNextX + " " +
                                        zombie.ZombieNextY);
            }
            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");

            Console.WriteLine();

            if (zombies.Count > 0)
            {
                int coordX = 0;
                int coordY = 0;

                for (int i = 0; i < zombies.Count; i++)
                {
                    double dist1 = 0;
                    double dist3 = 0;

                    var dist2 = CalculateDistanceMe(zombies.ElementAt(i), mySelf);
                    Console.Error.WriteLine("distance between zombie " + zombies.ElementAt(i).ZombieId + " and me is " + dist2);

                    for (int j = 0; j < humans.Count; j++)
                    {
                        dist1 = CalculateDistance(zombies.ElementAt(i), humans.ElementAt(j));
                        dist3 = CalculateDistanceHuman(mySelf, humans.ElementAt(j));

                        Console.Error.WriteLine("Zombie " + zombies.ElementAt(i).ZombieId + " are " + dist1 +
                                                "away from human" + humans.ElementAt(j).HumanId);
                        Console.Error.WriteLine("Distance between human " + humans.ElementAt(j).HumanId + " and me is " +
                                                dist3);

                        if (dist1 > dist3 || dist2 < dist1)
                        {
                            coordX = humans.ElementAt(j).HumanX;
                            coordY = humans.ElementAt(j).HumanY;
                        }
                        else if (dist2 < dist3 || dist2 < 2000)
                        {
                            coordX = zombies.ElementAt(i).ZombieX;
                            coordY = zombies.ElementAt(i).ZombieY;
                        }
                        else
                        {
                            coordX = zombies.ElementAt(i).ZombieNextX;
                            coordY = zombies.ElementAt(i).ZombieNextY;
//.........这里部分代码省略.........
开发者ID:AlexJCarstensen,项目名称:CodinGames,代码行数:101,代码来源:Program.cs

示例9: AlphaBetaSearch

        static void AlphaBetaSearch()
        {
            GameBoard parent = new GameBoard();
            parent.SetNodeType(GameBoard.MinMax.Min);
            int total_moves = 0;

            Console.WriteLine("Starting move:");
            displayBoard(parent);
            CalculateMoves(parent);

            bool turn = false; //turn 0 = player's turn(black,min), turn 1 = our turn(white,max)
            GameBoard next_move = parent;

            while (total_moves < 5000)
            {
                if (turn == false)//their turn (BLACK)
                {
                    Console.WriteLine("Their Move / Player 1");
                    //next_move = CalculateBeta(parent);

                    //Random Agent :(
                    //choose random child

                    if (parent.GetChildren().Count <= 0)
                    {
                        CalculateMoves(parent);
                    }

                    if (parent.GetChildren().Count <= 0)
                    {
                        break; //win condition for player 2
                    }

                    Random random_number = new Random();
                    int black_move = random_number.Next(parent.GetChildren().Count - 1);

                    next_move = parent.GetChildren().ElementAt(black_move);
                    turn = true;
                }
                else //my move (WHITE)
                {
                    Console.WriteLine("My Move / Player 2");

                    //next_move = null;
                    int best = 100000;

                    if (parent.GetChildren().Count <= 0)
                    {
                        CalculateMoves(parent);
                    }

                    if (parent.GetChildren().Count <= 0)
                    {
                        break; //win condition for player 1
                    }

                    //the parent is a max node (next_move)
                    //the children are min nodes
                    Collection<GameBoard> potentialMoves = new Collection<GameBoard>();

                    foreach (GameBoard child in parent.GetChildren())
                    {
                        CalculateAlphaBeta(child, 3, -100000, best, GameBoard.MinMax.Min);

                        if (child.GetAlphaBetaValue() < best)
                        {
                            best = child.GetAlphaBetaValue();
                            potentialMoves.Clear();
                            potentialMoves.Add(child);
                        }
                        else if (child.GetAlphaBetaValue() == best)
                        {
                            potentialMoves.Add(child);
                        }
                    }

                    Random random_number = new Random();
                    int white_move = random_number.Next(potentialMoves.Count - 1);
                    next_move = potentialMoves.ElementAt(white_move);

                    potentialMoves.Clear();
                    parent.SetAlphaBetaValue(best);
                    //System.GC.Collect();

                    turn = false;
                }
                //each move
                Console.WriteLine("Move #: " + total_moves);
                displayBoard(next_move);
                parent = next_move;
                total_moves++;
                next_move.SetParent(null);
                System.GC.Collect();

            }

            //WINNER
            if (next_move.GetNodeType() == GameBoard.MinMax.Max)
            {
                Console.WriteLine("Player 1 wins");
//.........这里部分代码省略.........
开发者ID:Bilzac,项目名称:457a,代码行数:101,代码来源:Assignment1b.cs


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