本文整理汇总了C#中System.Collections.Stack.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.ToArray方法的具体用法?C# Stack.ToArray怎么用?C# Stack.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Stack
的用法示例。
在下文中一共展示了Stack.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: PushingAndPopping
public void PushingAndPopping()
{
var array = new[] { 1, 2 };
Stack stack = new Stack(array);
stack.Push("last");
Assert.Equal(FILL_ME_IN, stack.ToArray());
var poppedValue = stack.Pop();
Assert.Equal(FILL_ME_IN, poppedValue);
Assert.Equal(FILL_ME_IN, stack.ToArray());
}
示例3: PushingAndPopping
public void PushingAndPopping()
{
var array = new[] { 1, 2 };
Stack stack = new Stack(array);
stack.Push("last");
Assert.Equal(new object[] { "last", 2, 1 }, stack.ToArray());
var poppedValue = stack.Pop();
Assert.Equal("last", poppedValue);
Assert.Equal(new object[] { 2, 1 }, stack.ToArray());
}
示例4: Main
static void Main(string[] args)
{
var stackOfValues = new Stack<string>();
GetInitialValuesFromArgs(args, ref stackOfValues);
var demoSet1 = new Set<string>(stackOfValues.ToArray());
Console.WriteLine(demoSet1.ToString());
var demoSet3 = new SortedSet(stackOfValues.ToArray());
Console.WriteLine(demoSet3.ToString());
Console.ReadKey();
}
示例5: PushingAndPopping
public void PushingAndPopping()
{
var array = new[] { 1, 2 };
Stack stack = new Stack(array);
stack.Push("last");
// Stack converts array into an array of objects.
Assert.Equal(new object[] { (string)"last", (int)2, (int)1 }, stack.ToArray());
//Pay attention to this format of declaring things! ^^^ 'object' is the type of thing that's going in each position,
// and in each position the type is specified.
var poppedValue = stack.Pop();
Assert.Equal("last", poppedValue);
Assert.Equal(new object[] { (int)2, (int)1}, stack.ToArray());
}
示例6: ReadPassword
public static string ReadPassword()
{
Stack<string> passbits = new Stack<string>();
for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true))
{
if (cki.Key == ConsoleKey.Backspace)
{
if (passbits.Count == 0)
continue;
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
Console.Write(" ");
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
passbits.Pop();
}
else
{
Console.Write("*");
passbits.Push(cki.KeyChar.ToString());
}
}
string[] pass = passbits.ToArray();
Array.Reverse(pass);
Console.Write(Environment.NewLine);
return string.Join(string.Empty, pass);
}
示例7: TestStackParamContrWrongParam
public void TestStackParamContrWrongParam()
{
Stack<int> stack = new Stack<int>(-2);
Assert.AreEqual(stack.Count, 0);
Assert.IsTrue(stack.IsEmpty);
CollectionAssert.AreEqual(stack.ToArray(), new int[0]);
}
示例8: Main
static void Main(string[] args)
{
string message = Console.ReadLine();
Stack stack = new Stack();
foreach (var item in message)
{
if (!IsCiphered(stack, item.ToString()))
{
stack.Push(item.ToString());
}
else
{
stack.Pop();
}
}
var result = stack.ToArray();
for (int i = result.Length - 1; i >= 0; i--)
{
Console.Write(result[i]);
}
}
示例9: FieldsToGBaseElementArray
/// <summary>
/// Converts an XMLstring to an array of GBaseElement (Name and Type) structures
/// </summary>
/// <param name="XMLString">An XML string of the form: field..type..field..type...</param>
/// <returns>An array of GBaseElement that is the parsed, passed XMLstring</returns>
public GBaseElement[] FieldsToGBaseElementArray(String XMLString)
{
Stack<GBaseElement> _elements = new Stack<GBaseElement>(); // Initially use a stack to hold the elements
XMLString = XMLString.Replace("\t", "").Replace("\r", "").Replace("\n", ""); // Replace the tabs, newllines, and returns in the string
// Loop until break is hit
while (true)
{
_GBaseElement.Name = XMLString.Substring(XMLString.IndexOf("Name=\"") + 6, // Set the name to be the string between "Name=\"" and the next "
XMLString.IndexOf("\"", XMLString.IndexOf("Name=\"") + 6) - (XMLString.IndexOf("Name=\"") + 6)).ToLower();
// Set the Type to be the string between <Type> and </Type>
_GBaseElement.Type = GetXMLBetweenTags("Type", XMLString).ToLower();
_elements.Push(_GBaseElement); // Push the newly generated object into _elements
XMLString = XMLString.Substring(XMLString.IndexOf("</Field>") + 8, // Get rid of the portion of the string that has been evaluated
XMLString.Length - (XMLString.IndexOf("</Field>") + 8));
if (XMLString.Replace(" ", "").Length == 0) // Get rid of any left over spaces (sometimes they presist) and see if there is no more to look over
break;
}
return _elements.ToArray(); // Return the stack as an array
}
示例10: ReadPassword
public static string ReadPassword()
{
var passbits = new Stack<string>();
//keep reading
for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true))
{
if (cki.Key == ConsoleKey.Backspace)
{
//rollback the cursor and write a space so it looks backspaced to the user
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
Console.Write(" ");
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
passbits.Pop();
}
else
{
Console.Write("*");
passbits.Push(cki.KeyChar.ToString());
}
}
string[] pass = passbits.ToArray();
Array.Reverse(pass);
Console.Write(Environment.NewLine);
return string.Join(string.Empty, pass);
}
示例11: InvokeViewShared
private ViewResult InvokeViewShared(string viewType, object model = null, string viewName = null)
{
Stack parameters = new Stack();
if (model == null)
{
if (viewName == null)
{
}
else
{
parameters.Push(viewName);
}
}
else
{
if (viewName == null)
{
parameters.Push(model);
}
else
{
parameters.Push(viewName);
parameters.Push(model);
}
}
return (ViewResult)_controller.GetType().GetMethod(viewType, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, parameters.Cast<Object>().Select(p => p.GetType()).ToArray(), null).Invoke(_controller, parameters.ToArray());
}
示例12: btCherche_Click
private void btCherche_Click(object sender, EventArgs e)
{
if (ComboPok閙on.Text != "")
{
try
{
//TODO modifier l'acc鑣 au pok閙on par l'index du combo
Pokemon p = X.PKlist[ComboPok閙on.SelectedIndex];
if (p.dependevo)
{
Pokemon evo = X.GetPok閙on(p.evolution.ToArray()[0].nom);
Pokemon p2 = new Pokemon();
X.CopyPokemon(p, p2);
p2.Oeuf1 = evo.Oeuf1;
p2.Oeuf2 = evo.Oeuf2;
X.argPokemon = p2;
}
else
X.argPokemon = p;
Stack<Capacite> cap = new Stack<Capacite>();
if (txtCapacit�Text == "" && txtCapacit�Text == "" && txtCapacit�Text == "" && txtCapacit�Text == "")
{
MessageBox.Show("Capacit� mal s閘ectionn�, click eul' nom dans la bo顃e!");
return;
}
if (txtCapacit�Text != "")
cap.Push(Xblood.GetCapacite(txtCapacit�Text));
if (txtCapacit�Text != "")
cap.Push(Xblood.GetCapacite(txtCapacit�Text));
if (txtCapacit�Text != "")
cap.Push(Xblood.GetCapacite(txtCapacit�Text));
if (txtCapacit�Text != "")
cap.Push(Xblood.GetCapacite(txtCapacit�Text));
X.argCapacite = cap.ToArray();
X.deepness = (int)NumUDDepth.Value;
lblBranches.Text = "";
lblLeaf.Text = "";
lblResult.Text = "Recherche...";
btChercher.Enabled = false;
btStop.Enabled = true;
t = new Thread(new ThreadStart(X.StartThread));
//t.Priority = ThreadPriority.AboveNormal;
t.Start();
timer1.Start();
}
catch
{
MessageBox.Show("Pok閙on mal s閘ectionn�, click eul' nom dans la bo顃e!");
}
}
else
TVr閟ultat.Nodes.Clear();
}
示例13: PushingAndPopping
public void PushingAndPopping()
{
var array = new[] { 1, 2 };
/*
Can an array have multiple types? Only an object array can?
*/
Stack stack = new Stack(array);
Console.WriteLine(stack);
stack.Push("last");
Assert.Equal(new object[] { (string)"last", (int)2, (int)1 }, stack.ToArray());
var poppedValue = stack.Pop();
Assert.Equal((string)"last", poppedValue);
Assert.Equal(new object[] { (int)2, (int)1 }, stack.ToArray());
/*
What is the difference between an array and a stack? The method of storing and retrieving the data. FIFO v. LIFO(FILO)
*/
}
示例14: GetPath
public TreePath GetPath(Node node) {
if (node == root)
return TreePath.Empty;
else {
Stack<object> stack = new Stack<object>();
while (node != root) {
stack.Push(node);
node = node.Parent;
}
return new TreePath(stack.ToArray());
}
}
示例15: Convert
/// <summary>
/// Convert a number to another base system based on the system's table
/// </summary>
public static string Convert(UInt64 number, string charactersTable)
{
var result = new Stack();
var radix = (UInt64)charactersTable.Length;
do
{
var m = number % radix;
result.Push(charactersTable[(int)m]);
number /= radix;
} while (number > 0);
return string.Join(string.Empty, result.ToArray());
}