本文整理汇总了C#中Queue.Take方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Take方法的具体用法?C# Queue.Take怎么用?C# Queue.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Take方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Console.Write("Enter first element of the sequence S1: ");
string line = Console.ReadLine();
int S1;
while (!int.TryParse(line, out S1))
{
Console.Write("Please enter an integer: ");
line = Console.ReadLine();
}
Console.WriteLine();
Console.Write("Enter number of the first sequence elements to be printed: ");
line = Console.ReadLine();
int N;
while (!(int.TryParse(line, out N) && (N > 0)))
{
Console.Write("Please enter a positive integer: ");
line = Console.ReadLine();
}
Console.WriteLine();
Queue<int> sequence = new Queue<int>(N);
sequence.Enqueue(S1);
int index = 0;
int currentElement = sequence.ElementAt(index);
int counter = 1;
while (counter < N)
{
sequence.Enqueue(currentElement + 1);
sequence.Enqueue(2 * currentElement + 1);
sequence.Enqueue(currentElement + 2);
index++;
currentElement = sequence.ElementAt(index);
counter += 3;
}
Console.WriteLine("First {0} members of the sequence are: ", N);
Console.WriteLine(String.Join(" ", sequence.Take(N)));
Console.WriteLine();
}
示例2: Main
static void Main()
{
int startElement = int.Parse(Console.ReadLine());
var result = new Queue<int>(50);
var start = DateTime.Now;
for (int i = 0; i < 100000; i++)
{
int element = startElement;
var sequence = new Queue<int>(50);
result = new Queue<int>(50);
sequence.Enqueue(element);
result.Enqueue(element);
while (result.Count < 50)
{
element = sequence.Dequeue();
int firstElement = element + 1;
int secondElement = 2 * element + 1;
int thirdElement = element + 2;
sequence.Enqueue(firstElement);
sequence.Enqueue(secondElement);
sequence.Enqueue(thirdElement);
result.Enqueue(firstElement);
result.Enqueue(secondElement);
result.Enqueue(thirdElement);
}
}
var duration = DateTime.Now - start;
Console.WriteLine(duration);
for (int i = 0; i < 50; i++)
{
Console.Write(result.Dequeue() + " ");
}
Console.WriteLine();
return;
Console.WriteLine(string.Join(" ", result.Take(50)));
}
示例3: ExpandDirectoryEntryMatches
IEnumerable<string> ExpandDirectoryEntryMatches(string path)
{
Queue<string> remaining = new Queue<string>(path.Split('\\'));
List<string> matches = new List<string>();
if (remaining.Count == 0)
{
return matches;
}
try
{
string base_path = String.Join(@"\", remaining.Take(remaining.Count - 1));
NtDirectory root_dir = GetDrive().DirectoryRoot;
// We'll first try the general case of unglobbed dir and a globbed final name.
using (NtDirectory base_dir =
remaining.Count > 1 ? NtDirectory.Open(base_path, root_dir, DirectoryAccessRights.Query)
: root_dir.Duplicate(DirectoryAccessRights.Query))
{
AddMatches(base_dir, BuildRelativePath(base_path, String.Empty), new string[] { remaining.Last() }, matches);
}
}
catch (NtException)
{
// If we couldn't open the drive then try brute force approach.
AddMatches(GetDrive().DirectoryRoot, String.Empty, remaining, matches);
}
return matches.Select(s => NTPathToPS(BuildDrivePath(s)));
}
开发者ID:CaledoniaProject,项目名称:sandbox-attacksurface-analysis-tools,代码行数:30,代码来源:NtObjectManagerProvider.cs
示例4: GetBlogDetailsByScore
public IList<IBlogDetail> GetBlogDetailsByScore(int count)
{
// 1.) retrieve from our analytics provider the names of hte top scored items.
IList<string> tagNames = AnalyticsService.GetRankedTagNames();
var returnList = new Queue<IBlogDetail>();
foreach (var tag in tagNames)
{
// 2.) Create our query per tag.
var query = string.Format("fast:{0}//*[@@templateid='{2}' and @@name='{3}')]", Context.SiteStartPath,
DataTemplateIds.BlogDetail.ToUpper(), tag);
Logger.Debug(string.Format("Running the query {0}", query), this);
var queryResult = Context.Query<IBlogDetail>(query);
if (queryResult != null)
{
foreach (var result in queryResult)
{
returnList.Enqueue(result);
}
}
// 3.) If we're over our query return list, yes I should perform this ahead of time but we're
// like a few minutes from deadline!
if (returnList.Count > count)
{
return returnList.Take(count).ToList();
}
}
return returnList.ToList();
}
示例5: TakeTest
public void TakeTest()
{
var queue = new Queue();
for(int i = 0; i < 100; i++)
{
queue.Enqueue(i.ToString());
}
Assert.AreEqual(100, queue.Count);
Assert.AreEqual("0", queue.Take(0));
Assert.AreEqual("1", queue.Take(1));
Assert.AreEqual("2", queue.Take(2));
Assert.AreEqual(100, queue.Count);
var items = queue.Take(10, 10);
var index = 10;
Assert.AreEqual(100, queue.Count);
foreach(var item in items)
{
Assert.AreEqual(index++.ToString(), item);
}
Assert.AreEqual(20, index);
}