本文整理汇总了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 };
}
}
}
示例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;
}
}
}
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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()) + "}";
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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>();
}
示例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");
}
示例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>();
}
示例14: GenerateGraph
public DirectedGraph GenerateGraph()
{
nodes = new List<DirectedGraphNode>();
links = new List<DirectedGraphLink>();
GenerateNodes();
return new DirectedGraph { Nodes = nodes.ToArray(), Links = links.ToArray() };
}
示例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;
}