linked list in 2.0 and the error:
-
Guys, I am trying to do the following but I get some conversion errors. can someone help me please? Class: public class Widget { public string RSP = ""; public int WidgetOrDiscount = 0; public decimal Price = 0.0m; } Console apps: static void Main(string[] args) { //LinkedList<System.String> myList = new LinkedList<System.String>(); LinkedList<Assignment3.Widget> myList = new LinkedList<Assignment3.Widget>(); PopulateData(ref myList); } private static void PopulateData(ref LinkedList<Widget> myList) { //record 001 Widget wdg1 = new Assignment3.Widget(); wdg1.RSP = "R"; wdg1.WidgetOrDiscount=150; wdg1.Price=1.00m; myList.AddFirst(wdg1); //record 002 Widget wdg2 = new Assignment3.Widget(); wdg2.RSP = "R"; wdg2.WidgetOrDiscount = 130; wdg2.Price = 2.00m; myList.AddAfter(wdg1, wdg2); //record 003 Widget wdg3 = new Assignment3.Widget(); wdg3.RSP = "S"; wdg3.WidgetOrDiscount = 145; wdg3.Price =0.00m; myList.AddAfter(wdg2, wdg3); //record 004 Widget wdg4 = new Assignment3.Widget(); wdg4.RSP = "R"; wdg4.WidgetOrDiscount = 50; wdg4.Price = 2.50m; myList.AddAfter(wdg3, wdg4); } Please help me.
-
Guys, I am trying to do the following but I get some conversion errors. can someone help me please? Class: public class Widget { public string RSP = ""; public int WidgetOrDiscount = 0; public decimal Price = 0.0m; } Console apps: static void Main(string[] args) { //LinkedList<System.String> myList = new LinkedList<System.String>(); LinkedList<Assignment3.Widget> myList = new LinkedList<Assignment3.Widget>(); PopulateData(ref myList); } private static void PopulateData(ref LinkedList<Widget> myList) { //record 001 Widget wdg1 = new Assignment3.Widget(); wdg1.RSP = "R"; wdg1.WidgetOrDiscount=150; wdg1.Price=1.00m; myList.AddFirst(wdg1); //record 002 Widget wdg2 = new Assignment3.Widget(); wdg2.RSP = "R"; wdg2.WidgetOrDiscount = 130; wdg2.Price = 2.00m; myList.AddAfter(wdg1, wdg2); //record 003 Widget wdg3 = new Assignment3.Widget(); wdg3.RSP = "S"; wdg3.WidgetOrDiscount = 145; wdg3.Price =0.00m; myList.AddAfter(wdg2, wdg3); //record 004 Widget wdg4 = new Assignment3.Widget(); wdg4.RSP = "R"; wdg4.WidgetOrDiscount = 50; wdg4.Price = 2.50m; myList.AddAfter(wdg3, wdg4); } Please help me.
AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
I used addbefore and addafter. how can I loop to display the items in a console app for the linked lists? I see online saying >ForEachLoop but it does not work,
1st, I think it's better that you write your LinkedList like this:
LinkedList<string> ll = new LinkedList<string>();
LinkedListNode<string> lln = new LinkedListNode<string>(Console.ReadLine());ll.AddFirst(lln);
LinkedListNode<string> Prelln = null;while (true)
{
Prelln = lln; // Save the current Node,string input = Console.ReadLine(); if (input == "End") // If user type "End", Done! break; lln = new LinkedListNode<string>(input); // Otherwise, Add a new Node ll.AddAfter(Prelln, lln); // Add new Node after previous saved Node
}
It takes less memory. [Edit] However, It's your choice ;) [\Edit] 2nd, a simple foreach gets you your nodes, for this example:
foreach (string i in ll)
Console.WriteLine(i);While (true) { Human.isLearnable = true; }
modified on Tuesday, October 21, 2008 2:41 PM