|
Hi,
I've got an issue concerning dictionaries.
The situation is like this.
I've got a database with a table containing peoples and their functions. Now, I want a dictionary with the functions as key, and all the corresponding people in a IEnumerable-list as value.
So, something like this:
("Student", "Joe Palmer, Marc Speed, Scott Roberts")
("Teacher", "Felipe Bauer, Lewis Hamilton, Jenson Spencer")
("Administration", "Mike Stanford", "Philip Carrey")
Where the function is the key, and the names are the values. So the first element of the dictionary has "student" as key, and a collection of 3 names as value.
Could someone help me out with this? I've tried to accomplish this, but I keep on struggling...
Many thanks in advance!
Greetz,
Mark
|
|
|
|
|
go for a Dictionary<string, List<Person>>
The add operation takes a test, akin to:
public void add(string function, Person person) {
if (!dictionary.ContainsKey(function)) dictionary.Add(new List<Person>());
List<Person> persons=dictionary[function];
persons.Add(person);
}
|
|
|
|
|
Thanks!
It was so simple when I saw your solution... 
|
|
|
|
|
You're welcome.
|
|
|
|
|
I'm trying to read in a list of VS2010 Projects from the registry:
private const string VS_PROJECT_MRU_PATH = @"Software\Microsoft\VisualStudio\10.0\ProjectMRUList";
public static List<string> GetSubKeyNodeNames(BaseKey BaseKey, string SubKey)
{
List<string> retVal = null;
RegistryKey baseKey;
if (SubKey != "")
{
baseKey = _GetRegistryBaseKey(BaseKey);
baseKey = baseKey.OpenSubKey(SubKey, false);
}
else
{
baseKey = _GetRegistryBaseKey(BaseKey);
}
if (baseKey == null && SubKey != "")
{
throw new Exception("Registry subkey not found");
}
else
{
string[] names = baseKey.GetValueNames();
retVal = (from n in names
select n).ToList();
}
return retVal;
}
I have verified that the key DOES indeed exist. I just doesn't open. The problem is similar to this[^] except that I'm reading from HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE.
Anyone know what;s going on here?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
I don't know what's going on, but have you stepped through your function _GetRegistryBaseKey(BaseKey) to see why it returns null?
Jack of all trades ~ Master of none.
|
|
|
|
|
Where is the method _GetRegistryBaseKey() defined and what value is it supposed to return?
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Here it is. This part works.
private static RegistryKey _GetRegistryBaseKey(BaseKey BaseKey)
{
RegistryKey key = null; ;
switch (BaseKey)
{
case BaseKey.HKEY_CLASSES_ROOT:
key = Registry.ClassesRoot;
break;
case BaseKey.HKEY_CURRENT_CONFIG:
key = Registry.CurrentConfig;
break;
case BaseKey.HKEY_CURRENT_USER:
key = Registry.CurrentUser;
break;
case BaseKey.HKEY_DYN_DATA:
key = Registry.DynData;
break;
case BaseKey.HKEY_LOCAL_MACHINE:
key = Registry.LocalMachine;
break;
case BaseKey.HKEY_PERFORMANCE_DATA:
key = Registry.PerformanceData;
break;
}
return key;
}
Everything makes sense in someone's mind
|
|
|
|
|
Works fine on my machine compiled as x86, x64 and Any CPU. Does your app run in restricted mode or is it a silverlight / web app or something? Does it run under a different user? Such as a service, web service, etc?
Seems like a security / permission problem to me.
|
|
|
|
|
SledgeHammer01 wrote: Seems like a security / permission problem to me.
That's what I thought, but I'm running as an admin, with no restrictions that I know of. It's a WPF app.
Everything makes sense in someone's mind
|
|
|
|
|
Do you have a try / catch hiding exceptions at some level? That method throws an exception on errors. Looking at the .Net source, the only way you should get a null is if the Win32 native function is returning an error other then security. Unfortunately, .Net hides the real error code from you. You might want to call the native RegOpenKeyEx through interop so you can get the real error code.
|
|
|
|
|
Based on your previous message, this cannot be true, since you stated that the key returned from this method is null . You need to use your debugger to see what value is being passed in to your code in the first place.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
I said OpenSubKey is returning False.
_GetRegistryBaseKey return the correct base key. Then the call to OpenSubKey returns False.
Everything makes sense in someone's mind
|
|
|
|
|
Well my previous comment still stands; you need to use your debugger to check all values to determine why OpenSubKey() returns null . With the information you have provided it's impossible to guess what values exist within your application.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Hi,
I have done some searching for this and have not found exactly what I need.
I have created a Windows Application in C#, Dot Net Framework 2, for my company. It currently has a Target Platform of "any cpu".
The company is slowly migrating to use 64 bit machines. Also we would like to upgrade the Windows Application to Dot Net Framework 4.
Management wants to be sure that changing to an x86 target platform (this is the target platform that needs to be used for both x32 and x64 bit machines to run the application) and changing to Dot Net Framework 4, will not break anything.
So: For testing, I want to create 2 applications with the same source code.
1) (Using Visual Studio 2005 to build and publish): Current Visual Studio settings: Dot Net Framework 2, and Target Platform: any cpu
2) (Using Visual Studio 2010 to build and publish): Dot Net Framework 4, and Target Platform: x86
In a label on the application, I want to display the Dot Net Version (I know how to do that). Then I also want to display the Target Platform, which will either be : "any cpu" or "x86".
After searching the internet for about 15 minutes, I discovered how to differentiate between, x32 and x64; or perhaps between x32 and x86... This is by simply using the IntPtr.Size property.
But.. How would I differentiate between "any cpu" and x86. Or what if I wanted to differentiate between x86 and x64?
Thanks in advance for any advice anyone can give me with this.
Anne
|
|
|
|
|
The whole idea of the 'Any CPU' setting is that it runs on both x86 (32 bit) and x64 (64 bit). Unless you're running into a specific problem that can be resolved by selecting x86 or x64, you should probably leave that setting on Any CPU.
Now to answer your actual question:
If you build x86, you will then IntPtr.Size will be 4. If you build x64 IntPtr.Size will be 8. If you build Any CPU, IntPtr.Size will be 4 on 32 bit windows and 8 on 64 bit windows. So that won't help identify the Any CPU compiler setting.
So, you would need to create 3 project files (2 copies of the original), then add a Conditional Compilation Symbol in each of the project files. Then set the Label's text based on those symbols.
string platformTarget = "unknown";
#if x86
platformTarget = "x86";
#elif x64
platformTarget = "x64";
#elif AnyCPU
platformTarget = "AnyCPU";
#endif
lblPlatformTarget = platformTarget;
You can do something similar with comparing Framework 2 and 4. The upgrade from 2 to 4 should be completely painless.
|
|
|
|
|
any cpu:32 bit machine
x86: 32bit or 64 bit machine
x64: 64 bit machine
|
|
|
|
|
don't think so.
|
|
|
|
|
x86 could run in x64 platform and x32 platform. I used.
|
|
|
|
|
any cpu: 32 bit machine code runs in 64-bit mode on Win64, in 32-bit mode otherwise (i.e. Windows decides based on Win itself and CPU)
x86: 32bit or 64 bit machine code runs in 32-bit mode (or not at all when future x64 CPUs no longer support x86)
x64: code runs in 64-bit mode on x64 CPUs and Win64, or not at all.
For all of them, the process needs to be homogeneous; if parts (referenced DLLs) contain native code of the other persuasion, the app won't load.
|
|
|
|
|
I see.
Thank you very much.

|
|
|
|
|
Apart from the application, you should also test your development environment: developing 32bit applications with VisualStudio 2010 on a Windows 7 (64bit) computer may require some strange settings - it was hard to get it working correctly in our case. Therefore, test also that point.
|
|
|
|
|
Hello,
What is good practice to load an object from a data source?
1 - Static method that returns the object.
2 - Constructor with parameter.
Thank you.
|
|
|
|
|
Use a DataReader .
Yes, if it's merely filling an ActiveRecord-object, then I'd expect initialization using a constructor. No, if it's merely a query that returns a value or a reader, then I'd expect a static method that returns that.
Bastard Programmer from Hell
|
|
|
|
|
The problem with best practices is they are different for different projects and usages. It's your job to understand what the practice is, how it should be used and whether it fits for the goals in your particular usage.
Failure is not an option; it's the default selection.
|
|
|
|