本文整理汇总了C#中Stack.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.ToArray方法的具体用法?C# Stack.ToArray怎么用?C# Stack.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeBrush
public IBrush MakeBrush(Player player, CommandReader cmd) {
if (player == null)
throw new ArgumentNullException("player");
if (cmd == null)
throw new ArgumentNullException("cmd");
Stack<Block> blocks = new Stack<Block>();
while (cmd.HasNext) {
Block block;
if (!cmd.NextBlock(player, false, out block))
return null;
blocks.Push(block);
}
switch (blocks.Count) {
case 0:
player.Message("{0} brush: Please specify the replacement block type.", Name);
return null;
case 1:
return new ReplaceNotBrush(blocks.ToArray(), Block.None);
default: {
Block replacement = blocks.Pop();
return new ReplaceNotBrush(blocks.ToArray(), replacement);
}
}
}
示例2: Main
static void Main()
{
var test = new Stack<int>();
test.Push(1);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(2);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(3);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(4);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(5);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(6);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Push(7);
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The stack count: {0}", test.Count);
test.Pop();
test.Pop();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The stack count: {0}", test.Count);
Console.WriteLine(test.Peek());
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The stack count: {0}", test.Count);
test.Clear();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The stack count: {0}", test.Count);
//test.Pop(); //if uncommented this line should throw exception
}
示例3: Test2
public void Test2()
{
var stack = new Stack<int>(new[] { 6, 6, 8, 6, 6, 5, 4, 6, 3, 1, 2, 1, 1, 1 });
var before = stack.ToArray();
_06.sortStack(stack);
var after = stack.ToArray();
}
示例4: DoTest
public static void DoTest ()
{
int top;
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
stack.Push(4);
stack.Push(5);
stack.Push(6);
Console.WriteLine("Stack:\r\n" + stack.ToHumanReadable());
Debug.Assert (stack.Top == 6, "Wrong top value.");
var array = stack.ToArray();
Debug.Assert (array.Length == stack.Count, "Wrong size!");
top = stack.Pop();
Debug.Assert (stack.Top == 5, "Wrong top value.");
Console.WriteLine("Old 2nd-last: " + top);
Console.WriteLine("Stack:\r\n" + stack.ToHumanReadable());
stack.Pop();
stack.Pop();
Debug.Assert (stack.Top == 3, "Wrong top value.");
Console.WriteLine("Stack:\r\n" + stack.ToHumanReadable());
var array2 = stack.ToArray();
Debug.Assert (array2.Length == stack.Count, "Wrong size!");
}
示例5: TestToArrayBasic
public void TestToArrayBasic()
{
Stack stk1;
Object[] oArr;
Int32 iNumberOfElements;
String strValue;
//[] Vanila test case - this gives an object array of the values in the stack
stk1 = new Stack();
oArr = stk1.ToArray();
Assert.Equal(0, oArr.Length);
iNumberOfElements = 10;
for (int i = 0; i < iNumberOfElements; i++)
stk1.Push(i);
oArr = stk1.ToArray();
Array.Sort(oArr);
for (int i = 0; i < oArr.Length; i++)
{
strValue = "Value_" + i;
Assert.Equal((Int32)oArr[i], i);
}
}
示例6: Read
public static void Read()
{
{
string path = @"D:\test\Untitled.png";
string path1 = @"D:\test\file1.txt";
string path2 = @"D:\test\file2.txt";
byte[] imagebyte = File.ReadAllBytes(path);
byte[] fileOne = null;
byte[] fileTwo = null;
Stack<byte> byt = new Stack<byte>();
for (int i = 0; i < imagebyte.Length; i++)
{
if (i % 2 == 0)
byt.Push(imagebyte[i]);
else
byt.Push(imagebyte[i]);
}
fileOne = byt.ToArray();
fileTwo = byt.ToArray();
if (fileOne != null)
File.WriteAllBytes(path1, fileOne);
if (fileOne != null)
File.WriteAllBytes(path2, fileTwo);
Console.WriteLine("file read");
Console.ReadLine();
}
}
示例7: GetWork
private Dictionary<int, string> GetWork()
{
TimeSpan hold = TimeSpan.FromMinutes(90);
Dictionary<int, string> all = new Dictionary<int, string>();
var messages = Queue.GetMessages(32, hold).ToList();
Stack<Task> tasks = new Stack<Task>(2000);
while (messages.Count > 0)
{
foreach (var message in messages)
{
string s = message.AsString;
JObject json = JObject.Parse(s);
int curId = json["cantonCommitId"].ToObject<int>();
if (!all.ContainsKey(curId))
{
all.Add(curId, s);
}
else
{
Console.WriteLine("Dupe id!");
}
tasks.Push(Queue.DeleteMessageAsync(message));
if (all.Count % 10000 == 0)
{
Console.WriteLine(all.Count);
}
}
// stop if we aren't maxing out
if (messages.Count == 32)
{
messages = Queue.GetMessages(32, hold).ToList();
}
else
{
messages = new List<CloudQueueMessage>();
}
if (tasks.Count > 2000)
{
Task.WaitAll(tasks.ToArray());
tasks.Clear();
}
}
Task.WaitAll(tasks.ToArray());
tasks.Clear();
return all;
}
示例8: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
Stack stk1;
Object[] oArr;
Int32 iNumberOfElements;
String strValue;
try
{
do
{
stk1 = new Stack();
oArr = stk1.ToArray();
iCountTestcases++;
if(oArr.Length!=0)
{
iCountErrors++;
Console.WriteLine("Err_752dsg! Expected value not returned, " + oArr.Length);
}
iNumberOfElements = 10;
for(int i=0; i<iNumberOfElements; i++)
stk1.Push(i);
oArr = stk1.ToArray();
Array.Sort(oArr);
iCountTestcases++;
for(int i=0; i<oArr.Length;i++)
{
strValue = "Value_" + i;
if((Int32)oArr[i] != i)
{
iCountErrors++;
Console.WriteLine("Err_7423fg! Expected value not returned, " + (Int32)oArr[i]);
}
}
} while (false);
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例9: GetNormalizedPath
public static string GetNormalizedPath(string path)
{
path = path.Replace('/', '\\');
string[] strArray = path.Split(new char[1]
{
'\\'
}, StringSplitOptions.RemoveEmptyEntries);
Stack<string> stack = new Stack<string>();
foreach (string str in strArray)
{
if (!(str == "."))
{
if (str == "..")
{
if (stack.Count == 0)
throw new ArgumentException("Invalid path can't start with '..'");
stack.Pop();
}
else
stack.Push(str);
}
}
string[] array = stack.ToArray();
Array.Reverse((Array) array);
return Utilities.Join<string>("\\", array);
}
示例10: GetExtensions
public Extension[] GetExtensions()
{
Stack<Extension> extStack = new Stack<Extension>();
extStack.Push(new Extension("InfoExt", "Information Extension", "Provides key information", new InfoExt()));
extStack.Push(new Extension("Events", "Event Extension", "Provides access to C# Event driven stuff.", new Events()));
return extStack.ToArray();
}
示例11: SumArrays
//adding Arrays from exc. 8
static int[] SumArrays(int[] first, int[] second)
{
Stack<int> addNumbers = new Stack<int>();
int maxLength = Math.Max(first.Length, second.Length);
// getting arrays lengths equal by shallow copy them to two new ones
int[] a = new int[maxLength];
int[] b = new int[maxLength];
Array.Copy(first, 0, a, maxLength - first.Length, first.Length);
Array.Copy(second, 0, b, maxLength - second.Length, second.Length);
// calculating sum
int carry = 0;
for (int i = maxLength - 1; i >= 0; i--)
{
addNumbers.Push((a[i] + b[i] + carry) % 10);
carry = (a[i] + b[i] + carry) / 10;
}
// adding last remainder
if (carry > 0)
addNumbers.Push(carry);
return addNumbers.ToArray();
}
示例12: ToBaseString
/// <summary>
/// Converts a <see cref="BigInteger"/> to its equivalent string representation that is encoded with base digits specified.
/// </summary>
/// <param name="value">A <see cref="BigInteger"/> that will be encoded.</param>
/// <param name="baseDigits">The base digits used to encode with.</param>
/// <returns>The string representation, in base digits, of the contents of <paramref name="value"/>.</returns>
public static string ToBaseString(BigInteger value, string baseDigits)
{
if (baseDigits == null)
throw new ArgumentNullException("baseDigits");
if (baseDigits.Length < 2)
throw new ArgumentOutOfRangeException("baseDigits", "Base alphabet must have at least two characters.");
// same functionality as Convert.ToBase64String
if (value == BigInteger.Zero)
return string.Empty;
bool isNegative = value.Sign == -1;
value = isNegative ? -value : value;
int length = baseDigits.Length;
var result = new Stack<char>();
do
{
BigInteger remainder;
value = BigInteger.DivRem(value, length, out remainder);
result.Push(baseDigits[(int)remainder]);
} while (value > 0);
// if the number is negative, add the sign.
if (isNegative)
result.Push('-');
// reverse it
return new string(result.ToArray());
}
示例13: CompareStacks
public static void CompareStacks(Stack<MuftecStackItem> runtimeStack, Stack<MuftecStackItem> runtimeStackExpected)
{
var actualArr = runtimeStack.ToArray();
var expectedArr = runtimeStackExpected.ToArray();
CompareArrays(actualArr, expectedArr);
}
示例14: Main
static void Main()
{
Stack<int> myStack = new Stack<int>();
myStack.Push(1);
myStack.Push(2);
myStack.Push(3);
myStack.Push(4);
myStack.Push(5);
myStack.Push(6);
int[] stackToArray = myStack.ToArray();
Console.Write("{");
for (int i = 0; i < stackToArray.Length-1; i++)
{
Console.Write(stackToArray[i] + ", ");
}
Console.Write(stackToArray[stackToArray.Length-1]+"}");
Console.WriteLine();
Console.WriteLine("the count="+myStack.Count);
Console.WriteLine();
Console.WriteLine(myStack.Peek());
Console.WriteLine(myStack.Pop());
Console.WriteLine(myStack.Peek());
Console.WriteLine(myStack.Pop());
Console.WriteLine(myStack.Peek());
Console.WriteLine("the count="+myStack.Count);
Console.WriteLine(myStack.Contains(111));
myStack.Clear();
Console.WriteLine("the count="+myStack.Count);
}
示例15: GetPathElements
private static string[] GetPathElements(string path)
{
string[] strArrays = path.Split(SendAsTrustedIssuerProperty.separators);
Stack<string> strs = new Stack<string>();
string[] strArrays1 = strArrays;
for (int i = 0; i < (int)strArrays1.Length; i++)
{
string str = strArrays1[i];
if (!(str == ".") && !(str == string.Empty))
{
if (str != "..")
{
strs.Push(str);
}
else
{
if (strs.Count > 0)
{
strs.Pop();
}
}
}
}
string[] array = strs.ToArray();
Array.Reverse(array);
return array;
}