Home
Products
Forums
Help
Publish Article
Go Freelance

How to write link list in C#

The following code demonstrates how to write amd use a link list in C#.

using System;

namespace PardesiServices
{
	class LinkList
	{
		public string Val;
		public object NextItem;
		[STAThread]
		static void Main(string[] args)
		{
			LinkList obList = new LinkList();
			obList.Val = "Head";
			
			LinkList obHead = obList;
			
			// Add 10 items to the list.
			for (int i = 0; i < 10; i++)
			{
				obList.NextItem = new LinkList();
				obList = (LinkList)obList.NextItem;
				obList.Val = i.ToString();
			}

			// Print the added items.
			while (obHead != null)
			{
				Console.WriteLine("Item: {0}", obHead.Val);
				obHead = (LinkList)obHead.NextItem;
			}
		}
	}

}
										
Go Freelance
Home     About us     Contact us    Copyright    Privacy Policy    Return Policy    Advertisers
Copyright © Netomatix