>It seems strange that the type returned isn't the type from the registry. Why wouldn't .Net return an Int if the registry key holds an int, or a string if the value is string?? That's what a WinAPI call would do. Seems to be it's more obscure now.I guess it was easier for them to just return an object.
>I guess I could return the object returned from GetValue, but then your code has to cast whenever it's used. What do you think of the idea of writing a wrapper GetValue method, overloaded for each default value? So if I pass an int as the default, then the return value is cast to int, likewise for other values being returned based on the default value passed in.But, this is definitely a better way to handle it ... a bunch of overloaded methods returning the proper type. I've written that kind of stuff lots of times. I really should play around more with generics though (I've been a bad MVP ... not keeping with some of the new stuff, and generics aren't all that new) ... because that may work too, instead of a lot of overloaded methods. But, I don't know for sure, not having tried it and not having the time right this minute to try it either. <g>
~~Bonnie
>
>
>
>>
>Now this is all fine when the registry value is a string, but it certainly isn't generic. What if the value is an int?>>
>>Have your method return an object rather than a string.
>>
>>~~Bonnie
>>
>>
>>
>>>I have this code:
>>>
>>>
>>>public string GetRegistryValue(string sKeyName, string sKeyValue)
>>>{
>>> sKeyPath = "Software\\my_app\\" + sKeyName;
>>>
>>> string sRetVal = (string)Registry.LocalMachine.GetValue(sKeyPath, sKeyValue, "");
>>>
>>> return sValue;
>>>}
>>>
>>>
>>>Now this is all fine when the registry value is a string, but it certainly isn't generic. What if the value is an int?
>>>
>>>
>>>Thanks