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


C# ICollection.ToArray方法代码示例

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


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

示例1: Tokenize

        /// <summary>
        /// Converts a collection of arguments into a collection of defined Tokens.
        /// </summary>
        /// <param name="args">The arguments received from the command line.</param>
        /// <param name="allowedPrefixes">The prefixes used to identify named arguments.</param>
        /// <returns></returns>
        public static IEnumerable<Token> Tokenize(IEnumerable<string> args, ICollection<char> allowedPrefixes = null)
        {
            int index = 0;
            allowedPrefixes = allowedPrefixes ?? _defaultPrefixes;

            foreach (var arg in args)
            {
                var prefixCount = CountStringStartsWith(arg, allowedPrefixes);
                // shortnamed
                if (prefixCount==1)
                {
                    // split multi shortname arguments into seperate fields
                    // '-am' becomes ['a','m']
                    foreach (char t in arg.TrimStart(allowedPrefixes.ToArray()))
                        yield return new Token { Index = ++index, Value = t.ToString(), Type = TokenType.Field };
                    
                }
                else if (prefixCount == 2) // longnames
                {
                    yield return new Token { Index = ++index, Value = arg.TrimStart(allowedPrefixes.ToArray()), Type = TokenType.Field };
                }
                else // values
                {
                    yield return new Token { Index = ++index, Value = arg, Type = TokenType.Value };
                }
            }
        }
开发者ID:clintcparker,项目名称:cliparse,代码行数:33,代码来源:Token.cs

示例2: CalculateNeighbors

 public static void CalculateNeighbors(ICollection<CubeViewModel> cubeViewModels)
 {
     // I'd like to eliminate this loop... but we have to reset everything before we can start processing neighbors
     foreach (var cube in cubeViewModels.Select(cubeViewModel => cubeViewModel.CubeModel))
     {
         cube.Neighbors = new Neighbors();
     }
     for (var i = 0; i < cubeViewModels.Count - 1; i++)
     {
         var cubeViewModel = cubeViewModels.ToArray()[i];
         var cubeViewModelX = cubeViewModel.PositionX;
         var cubeViewModelY = cubeViewModel.PositionY;
         var cube = cubeViewModel.CubeModel;
         for (var j = i + 1; j < cubeViewModels.Count; j++)
         {
             var otherCubeViewModel = cubeViewModels.ToArray()[j];
             // If anybody knows a better way to do this, please fix it.  The only way I could get
             // the DP to expose its value is through its ToString method...
             var otherCubeViewModelX = otherCubeViewModel.PositionX;
             var otherCubeViewModelY = otherCubeViewModel.PositionY;
             var otherCube = otherCubeViewModel.CubeModel;
             if ((Math.Abs(cubeViewModelX - otherCubeViewModelX) <= (Neighbors.GAP_TOLERANCE + Cube.dimension)) && (Math.Abs(cubeViewModelY - otherCubeViewModelY) <= (Cube.dimension - Neighbors.SHARED_EDGE_MINIMUM)))
             {
                 if (cubeViewModelX < otherCubeViewModelX)
                 {
                     cube.Neighbors.Right = otherCube;
                     otherCube.Neighbors.Left = cube;
                 }
                 else
                 {
                     cube.Neighbors.Left = otherCube;
                     otherCube.Neighbors.Right = cube;
                 }
             }
             if ((Math.Abs(cubeViewModelY - otherCubeViewModelY) <= (Neighbors.GAP_TOLERANCE + Cube.dimension)) && (Math.Abs(cubeViewModelX - otherCubeViewModelX) <= (Cube.dimension - Neighbors.SHARED_EDGE_MINIMUM)))
             {
                 if (cubeViewModelY < otherCubeViewModelY)
                 {
                     cube.Neighbors.Top = otherCube;
                     otherCube.Neighbors.Bottom = cube;
                 }
                 else
                 {
                     cube.Neighbors.Bottom = otherCube;
                     otherCube.Neighbors.Top = cube;
                 }
             }
         }
     }
 }
开发者ID:veatchje,项目名称:Siftables-477,代码行数:50,代码来源:NeighborCalculator.cs

示例3: Start

        public Task<HRESULT[]> Start(IList<OpcDaItem> items, ICollection<object> values,
            CancellationToken token)
        {
            try
            {
                var serverHandles = ArrayHelpers.GetServerHandles(items);
                
                HRESULT[] ppErrors;
                int cancelId =_asyncIO2.Write(serverHandles, values.ToArray(), TransactionId, out ppErrors);

                if (ppErrors.All(e => e.Failed)) // if all errors no callback will take place
                {
                    _requestManager.CompleteRequest(TransactionId);
                    _tcs.SetResult(ppErrors);
                }
                else
                {
                    CancellationId = cancelId;
                    RequestHelpers.SetCancellationHandler(token, Cancel);
                }
                return Task;
            }
            catch (Exception ex)
            {
                _requestManager.CompleteRequest(TransactionId);
                _tcs.SetException(ex);
                return Task;
            }
        }
开发者ID:yuriik83,项目名称:TitaniumAS.Opc.Client,代码行数:29,代码来源:WriteAsyncRequest.cs

示例4: FillFees

		public void FillFees(ICollection<AppraiserFee> fees, FeesViewModel feesViewModel)
		{
			if (fees == null)
			{
				throw new ArgumentNullException("fees");
			}
			if (feesViewModel == null)
			{
				throw new ArgumentNullException("fees view model");
			}
			var feesArray = fees.ToArray();
			foreach (var fee in feesArray)
			{
				if (!feesViewModel.FeesItems.Any(f => f.Id == fee.Id.ToString()))
				{
					fees.Remove(fee);
				}
			}
			foreach (var item in feesViewModel.FeesItems)
			{
				if (string.IsNullOrEmpty(_refManager.GetProductNameById(item.ProductType)))
				{
					throw new ArgumentException("product id");
				}
				var fee = fees.SingleOrDefault(e => e.Id.ToString() == item.Id);
				if (fee == null)
				{
					fee = new AppraiserFee();
					fees.Add(fee);
				}
				fee.Amount = item.Fee.Value;
				fee.ProductId = item.ProductType;
			}
		}
开发者ID:evkap,项目名称:DVS,代码行数:34,代码来源:FeeManager.cs

示例5: AppendToStream

        public async Task AppendToStream(IIdentity id, long expectedVersion, ICollection<IEvent> events)
        {
            if (events.Count == 0)
            {
                return;
            }

            var name = id.ToString();
            var data = this.serializer.SerializeEvent(events.ToArray());

            try
            {
                await this.appender.Append(name, data, expectedVersion);
            }
            catch (AppendOnlyStoreConcurrencyException e)
            {
                // load server events
                var server = await this.LoadEventStream(id, 0, int.MaxValue);
                // throw a real problem
                throw OptimisticConcurrencyException.Create(server.Version, e.ExpectedStreamVersion, id, server.Events);
            }

            foreach (var @event in events)
            {
                Logger.DebugFormat("{0} r{1} Event: {2}", id, expectedVersion, @event);
            }
        }
开发者ID:jaceenet,项目名称:TastyDomainDriven,代码行数:27,代码来源:EventStoreAsync.cs

示例6: EncodeIds

        private string EncodeIds(ICollection<int> ids)
        {
            if (ids == null || !ids.Any()) return string.Empty;

            // Using {1},{2} format so it can be filtered with delimiters.
            return "{" + string.Join("},{", ids.ToArray()) + "}";
        }
开发者ID:SmartFire,项目名称:Lombiq-Fields,代码行数:7,代码来源:MediaLibraryUploadField.cs

示例7: AppendToStream

        public void AppendToStream(IIdentity id, long originalVersion, ICollection<IEvent> events)
        {
            if (events.Count == 0)
                return;
            var name = IdentityToString(id);
            var data = SerializeEvent(events.ToArray());
            try
            {
                _appendOnlyStore.Append(name, data, originalVersion);
            }
            catch(AppendOnlyStoreConcurrencyException e)
            {
                // load server events
                var server = LoadEventStream(id, 0, int.MaxValue);
                // throw a real problem
                throw OptimisticConcurrencyException.Create(server.Version, e.ExpectedStreamVersion, id, server.Events);
            }

            // technically there should be a parallel process that queries new changes 
            // from the event store and sends them via messages (avoiding 2PC problem). 
            // however, for demo purposes, we'll just send them to the console from here
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            foreach (var @event in events)
            {
                Console.WriteLine("  {0} r{1} Event: {2}", id,originalVersion, @event);
            }
            Console.ForegroundColor = ConsoleColor.DarkGray;
        }
开发者ID:frankies,项目名称:lokad-iddd-sample,代码行数:28,代码来源:EventStore.cs

示例8: RankItems

        ///
        public override IList<int> RankItems(ICollection<int> users, ICollection<int> items)
        {
            var scores_by_user = new float[users.Count, items.Count];

            var users_array = users.ToArray();
            var items_array = items.ToArray();

            for (int u = 0; u < users.Count; u++)
                for (int i = 0; i < items.Count; i++)
                {
                    int user_id = users_array[u];
                    int item_id = items_array[i];
                    scores_by_user[u, i] = recommender.Predict(user_id, item_id);
                }

            var wins_by_item = new Dictionary<int, int>();
            foreach (int item_id in items)
                wins_by_item[item_id] = 0;

            for (int u = 0; u < users.Count; u++)
                for (int i = 0; i < items.Count; i++)
                    for (int j = 0; j < items.Count; j++)
                        if (scores_by_user[u, i] > scores_by_user[u, j])
                            wins_by_item[items_array[i]]++;

            var ranked_items = new List<int>(items);
            ranked_items.Sort(delegate(int i1, int i2) { return wins_by_item[i2].CompareTo(wins_by_item[i1]); } );

            return ranked_items;
        }
开发者ID:edwardt,项目名称:MyMediaLite,代码行数:31,代码来源:PairwiseWins.cs

示例9: EvaluateAll

		public EvaluationResult EvaluateAll(ICollection<Expression> expressions) {
			var evald = Array.ConvertAll(expressions.ToArray(), Evaluate);
			var fail = Array.FindIndex(evald, x => x.IsError);
			if(fail != -1)
				return evald[fail];
			var result = Array.ConvertAll(evald, x => x.Result);
			return Success(typeof(object[]), result);
		}
开发者ID:drunkcod,项目名称:Cone,代码行数:8,代码来源:ExpressionEvaluatorContext.cs

示例10: GetLowerHalfOfKeys

 private static HashSet<long> GetLowerHalfOfKeys(ICollection<long> numbers)
 {
     var sorted = numbers.ToArray();
     Array.Sort(sorted);
     var lh = new long[sorted.Length / 2];
     Array.Copy(sorted, lh, sorted.Length / 2);
     return lh.ToHashSet();
 }
开发者ID:dmitrynovik,项目名称:Stanford-Algo-2Sum-and-sum-of-medians-problem,代码行数:8,代码来源:Sum.cs

示例11: Select

 public IEnumerable<Socket> Select(ICollection<Socket> handles)
 {
     Console.Write("Waiting for pending connections...");
     var pending = new ArrayList(handles.ToArray());
     Socket.Select(pending, null, null, 10000);
     Console.WriteLine("done");
     return pending.Cast<Socket>();
 }
开发者ID:jeffrymorris,项目名称:reactor-pattern,代码行数:8,代码来源:SynchEventDemultiplexer.cs

示例12: Admin

 public ActionResult Admin(string user, ICollection<string> roles)
 {
     string[] rolesArr=Roles.GetRolesForUser(user);
      if (rolesArr.Count()!=0)
          Roles.RemoveUserFromRoles(user, rolesArr);
     if(roles!=null && roles.Count!=0)
         Roles.AddUserToRoles(user,roles.ToArray());
     return RedirectToAction("Admin", "Account");
 }
开发者ID:isel31519,项目名称:PI_1112i,代码行数:9,代码来源:AccountController.cs

示例13: GetAssetItemsForExport

 internal static IEnumerable<ExportPackageItem> GetAssetItemsForExport(ICollection<string> guids, bool includeDependencies)
 {
   if (guids.Count == 0)
     guids = (ICollection<string>) new HashSet<string>((IEnumerable<string>) AssetServer.CollectAllChildren(AssetServer.GetRootGUID(), new string[0]));
   ExportPackageItem[] exportPackageItemArray = PackageUtility.BuildExportPackageItemsList(guids.ToArray<string>(), includeDependencies);
   if (includeDependencies && ((IEnumerable<ExportPackageItem>) exportPackageItemArray).Any<ExportPackageItem>((Func<ExportPackageItem, bool>) (asset => InternalEditorUtility.IsScriptOrAssembly(asset.assetPath))))
     exportPackageItemArray = PackageUtility.BuildExportPackageItemsList(guids.Union<string>(InternalEditorUtility.GetAllScriptGUIDs()).ToArray<string>(), includeDependencies);
   return (IEnumerable<ExportPackageItem>) ((IEnumerable<ExportPackageItem>) exportPackageItemArray).Where<ExportPackageItem>((Func<ExportPackageItem, bool>) (val => val.assetPath != "Assets")).ToArray<ExportPackageItem>();
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:9,代码来源:PackageExport.cs

示例14: GenerateGraph

		public DirectedGraph GenerateGraph()
		{
			nodes = new List<DirectedGraphNode>();
			links = new List<DirectedGraphLink>();

			GenerateNodes();

			return new DirectedGraph { Nodes = nodes.ToArray(), Links = links.ToArray() };
		}
开发者ID:typesafe,项目名称:nuget.dgml,代码行数:9,代码来源:GraphGenerator.cs

示例15: SpriteWrapper

 /// <summary>
 /// Create a new SpriteWrapper.
 /// </summary>
 /// <param name="spritestart">The Collection of ISprites to initialize Sprites with.</param>
 /// <param name="sb">The SpriteBatch to use.</param>
 /// <param name="updates">The Updater to use for updating ISprite objects (in addition to the Update() method).</param>
 public SpriteWrapper(ICollection<ISprite> spritestart, SpriteBatch sb, Updater updates)
     : this(sb, spritestart.ToArray<ISprite>())
 {
     if (updates == null)
     {
         throw new ArgumentNullException("updates");
     }
     Updater = updates;
 }
开发者ID:KhkhkhTeMakhkhKh,项目名称:Glib,代码行数:15,代码来源:SpriteWrapper.cs


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