2 Replies - 764 Views - Last Post: 02 February 2009 - 11:25 AM Rate Topic: -----

#1 Poornima Mani  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 178
  • Joined: 25-January 09

Hashtable

Post icon  Posted 01 February 2009 - 11:55 PM

using System;
using System.IO;
public Hashtable ListAllSubDirectories(string dir)
	{
		//variable to hold our results
		Hashtable dirResults = new Hashtable();
		try
		{
			//get the root directory of the directory path provided
			Directory.GetDirectoryRoot(dir);
			//get the last location of a backslash ("\")
			int loc = dir.LastIndexOf('\\');
			//remove the last backslash
			dir = dir.Remove(loc, dir.Length - loc);
			//add the root to the HashTable
			dirResults.Add("Root Directory", dir);
			//create a string array to hold all the directories under the root
			string[] directories = Directory.GetDirectories(dir);
			foreach (string directory in directories)
			{
				dirResults.Add("SubDirectory:", directory);
			}
		}
		catch (Exception ex)
		{
			dirResults = null;
		   // MessageBox.Show(ex.Message);
		}
		return dirResults;
	}
}



In this code i am using hashtable to list all the directories of a drive.Please can anyone tell me where will the output be displayed?

Is This A Good Question/Topic? 0
  • +

Replies To: Hashtable

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Hashtable

Posted 02 February 2009 - 10:30 AM

It depends on what you are doing with the data after it is returned from this method. Currently, with the code you posted it is not being displayed at all.

Had you written this code you would have known that.
Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Hashtable

Posted 02 February 2009 - 11:25 AM

Using a hashtable the way this routine does will not work correctly. The whole point of a hashtable is that the keys are unique. Please read the documentation: Hashtable Class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1