本文整理汇总了C#中LinkedList.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedList.ToList方法的具体用法?C# LinkedList.ToList怎么用?C# LinkedList.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnRand_Click
private void btnRand_Click(object sender, EventArgs e)
{
Random r = new Random();
var sz = r.Next(8, 12);
int gap = this.ClientSize.Height / sz;
int width = this.ClientSize.Width;
LinkedList<PointF> points = new LinkedList<PointF>();
points.AddFirst(new PointF(width / 2,
(float)r.NextDouble() * gap));
for (int i = 1; i < sz - 1; i++)
{
bool putOnLeft = r.Next() % 2 == 0;
var widthOffset = r.NextDouble() * width / 4;
PointF p = new PointF(
(float)(putOnLeft ? width / 2 - widthOffset : width / 2 + widthOffset),
(float)(r.NextDouble() * gap + gap * i));
if (putOnLeft)
points.AddFirst(p);
else
points.AddLast(p);
}
points.AddFirst(new PointF(width / 2,
gap * sz - (float)r.NextDouble() * gap));
vertices = points.ToList();
reDrawPolygon(vertices);
}
示例2: AsIList_Enumerable_Copies
public void AsIList_Enumerable_Copies()
{
LinkedList<object> enumerable = new LinkedList<object>();
enumerable.AddLast(new object());
enumerable.AddLast(new object());
List<object> expected = enumerable.ToList();
IEnumerable<object> listAsEnumerable = enumerable;
IList<object> enumerableAsIList = listAsEnumerable.AsIList();
Assert.Equal(expected, enumerableAsIList);
Assert.NotSame(expected, enumerableAsIList);
}
示例3: Format
public List<JsToken> Format(List<JsToken> tokens)
{
Tokens = new LinkedList<JsToken>(tokens);
Events = new Stack<string>();
CurrentNode = Tokens.First;
Indent = 0;
Line = 1;
while (CurrentNode != null)
{
Process();
MoveNext();
}
Line = 1;
return Tokens.ToList();
}
示例4: ConnectPathsWithGivenSum
private static void ConnectPathsWithGivenSum(TreeNode<int> node, LinkedList<int> currentPath, IList<List<int>> allPaths, int sum)
{
currentPath.AddLast(node.Value);
if (node.Childrens.Count == 0 && currentPath.Sum() == sum)
{
allPaths.Add(currentPath.ToList());
return;
}
foreach (var child in node.Childrens)
{
ConnectPathsWithGivenSum(child, currentPath, allPaths, sum);
currentPath.RemoveLast();
}
}
示例5: add_item_in_middle_of_a_list_should_appear_in_the_correct_order
public void add_item_in_middle_of_a_list_should_appear_in_the_correct_order()
{
var list = new LinkedList<int>();
var one = 1;
var two = 2;
var three = 3;
list.AddHead(one);
list.AddTail(three);
list.AddBefore(list.Tail, two);
var result = list.ToList();
Assert.AreEqual(one, list.Head.Value);
Assert.AreEqual(two, result[1]);
Assert.AreEqual(three, list.Tail.Value);
}
示例6: GetShortestPath
public ShortestPath GetShortestPath(GraphNode start, GraphNode destination)
{
Initialize(destination);
start.BestDistance = 0f;
_consideredEdges = new LinkedList<GraphEdge>();
if (GetShortestPathRecursive(start, destination))
{
var path = new LinkedList<GraphNode>();
GraphNode current = destination;
path.AddFirst(current);
while (current != start)
{
current = current.Parent;
path.AddFirst(current);
}
return new ShortestPath(path.ToList(), _consideredEdges);
}
throw new ArgumentException("Startnode is not connected to destination node.");
}
示例7: ConnectLongestPathsInSubtree
private void ConnectLongestPathsInSubtree(Node<int> node, LinkedList<int> currentPath, IList<List<int>> allPaths, ref int maxLength)
{
currentPath.AddLast(node.Value);
if (node.Children.Count == 0 && currentPath.Count >= maxLength)
{
allPaths.Add(currentPath.ToList());
if (currentPath.Count > maxLength)
{
maxLength = currentPath.Count;
}
return;
}
foreach (var childNode in node.Children)
{
this.ConnectLongestPathsInSubtree(childNode, currentPath, allPaths, ref maxLength);
currentPath.RemoveLast();
}
}
示例8: ConnectLongestPath
private static void ConnectLongestPath(TreeNode<int> node, LinkedList<int> currentPath,
IList<List<int>> allPaths, ref int maxLength)
{
currentPath.AddLast(node.Value);
if (node.Childrens.Count == 0 && currentPath.Count >= maxLength)
{
allPaths.Add(currentPath.ToList());
if (currentPath.Count > maxLength)
{
maxLength = currentPath.Count;
}
return;
}
foreach (var child in node.Childrens)
{
ConnectLongestPath(child, currentPath, allPaths, ref maxLength);
currentPath.RemoveLast();
}
}
示例9: ConstructorWithInitializationListThenAddNegative
public void ConstructorWithInitializationListThenAddNegative()
{
var target = new LinkedList<int>() { -1, 0, 1 };
target.Add(-618);
CollectionAssert.AreEqual(new int[] { -1, 0, 1, -618 }, target.ToList());
}
示例10: ConstructorThenAddNegative
public void ConstructorThenAddNegative()
{
var target = new LinkedList<int>() { 1297 };
target.Add(-618);
CollectionAssert.AreEqual(new int[] { 1297, -618 }, target.ToList());
}
示例11: ConstructorThenAdd
public void ConstructorThenAdd()
{
var target = new LinkedList<int>() { 0 };
target.Add(654);
CollectionAssert.AreEqual(new int[] { 0, 654 }, target.ToList());
}
示例12: Serialize
public byte[] Serialize()
{
var previousStructures = new LinkedList<SessionStructure>();
foreach(var previousState in PreviousStates)
{
previousStructures.AddLast(previousState.Structure);
}
var record = new RecordStructure {
CurrentSession = SessionState.Structure,
PreviousSessions = previousStructures.ToList()
};
byte[] serialized;
using(var stream = new MemoryStream())
{
Serializer.Serialize<RecordStructure>(stream, record);
serialized = stream.ToArray();
}
return serialized;
}
示例13: GetPartialChain
/// <summary>
/// Returns the set of contiguous blocks between 'higher' and 'lower'. Higher is included, lower is not.
/// </summary>
/// <exception cref="BlockStoreException"/>
private IList<StoredBlock> GetPartialChain(StoredBlock higher, StoredBlock lower)
{
Debug.Assert(higher.Height > lower.Height);
var results = new LinkedList<StoredBlock>();
var cursor = higher;
while (true)
{
results.AddLast(cursor);
cursor = cursor.GetPrev(_blockStore);
Debug.Assert(cursor != null, "Ran off the end of the chain");
if (cursor.Equals(lower)) break;
}
return results.ToList();
}
示例14: Constructor_NodeParameter
public void Constructor_NodeParameter()
{
var target = new LinkedList<int>() { 0 };
CollectionAssert.AreEqual(new int[] { 0 }, target.ToList());
Assert.AreEqual(1, target.Count());
}
示例15: UpdateFolders
public JsonResult UpdateFolders(CatalogJobParameter catalogJob, string mailAddress)
{
var dataAccess = RestoreFactory.Instance.NewDataAccessForQuery();
dataAccess.CatalogJob = catalogJob;
var allFolder = dataAccess.GetAllFoldersInMailboxes(mailAddress);
var tree = TreeNode.CreateTree(allFolder);
List<Item> result = new List<Item>();
Stack<Item> stacks = new Stack<Item>();
int oldDepth = -1;
TreeNode.DepthFirstTraverseTree(tree, (currentNode, depth, inChildrenIndex) =>
{
Item item = null;
if (currentNode.Folder == null)
{
item = new Item();
}
else
{
item = new Item()
{
Id = currentNode.Folder.FolderId,
DisplayName = ((IItemBase)currentNode.Folder).DisplayName,
ChildCount = currentNode.Folder.ChildFolderCount + currentNode.Folder.ChildItemCount,
ItemType = ItemTypeStr.Folder,
OtherInformation = currentNode.Folder
};
}
if (oldDepth <= depth)
{
stacks.Push(item);
}
else
{
LinkedList<Item> childItems = new LinkedList<Item>();
var stackCount = stacks.Count;
for (int i = 0; i < inChildrenIndex; i++)
{
childItems.AddFirst(stacks.Pop());
}
item.Container = childItems.ToList();
stacks.Push(item);
}
oldDepth = depth;
});
var rootItem = stacks.Pop();
return Json(new { CatalogTime = catalogJob.StartTime, Details = rootItem.Container });
}