Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collection is removed from memory after a while
Message
De
15/11/2013 14:18:01
 
 
À
15/11/2013 14:12:15
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01588067
Message ID:
01588081
Vues:
26
J'aime (1)
>>Why don't you use a Dictionary< string, Tuple< int, int >> to store the image data ?
>>
>>You don't need to loop through the collection to find the image. You can retrieve the data with a simple TryGetValue()
>>
>>
>>	class ImageData
>>	{
>>		internal int Width  { get; private set;}
>>		internal int Height { get; private set; }
>>
>>		internal ImageData( int width, int height)
>>		{
>>		
>>			Width = width;
>>			Height = height;
>>		}
>>	}
>>
>>	static  class TestImage
>>	{
>>
>>		internal static void Go()
>>		{
>>			Dictionary<string, ImageData> images = new Dictionary<string,ImageData>();
>>
>>			images.Add("image1", new ImageData(10, 20));
>>			images.Add("image2", new ImageData(30, 40));
>>
>>			string s = "image4";
>>
>>			bool found = false;
>>			ImageData imagedata;
>>
>>
>>			if( images.TryGetValue(s, out imagedata) )
>>				found = true;
>>		
>>			
>>		}
>>	}
>>
>
>Thanks, I might try that. But, I need to know if this supports the detection of the presence of what I am looking for. As, I do not load all images in memory. Only certain amount of them are. So, this is why I need to look it up first to see if it is there. Then, I can retrieve the related information I need. Is the dictionary approach capable of looking up for an item first to let me know if it is present or not in the dictionary? If yes, can you adjust the sample to let me know how this should be done. Otherwise, I would assume I would have to Try/Catch. Then, if an error would be returned, it would mean it is not there.

The answer is in the sample

If TryGetValue() returns true, it was in

There's also ContainsKey() - but TryGetValue() tells you whether the image was in and if it was returns the data via the out parameter

http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform