Registry question (debug three lines of code for me?)

  • Thread starter Thread starter Jim Margarit
  • Start date Start date
J

Jim Margarit

copied from MSDN help on Registry class:

string[] tArray = (string[])Registry.GetValue(keyName,"TestArray",
newstring[] {"Default if TestArray does not exist."});

Here's my code:

string[] defaultExt = {".mp4",".avi"};
string[] validExts;
validExts = (string[])Registry.GetValue("myTest","validExts",defaultExt);

if the registry is empty, this always returns null. I'm expecting
{".mp4",".avi"}.

if I make the next line:

if (validExts = null) Registry.SetValue("myTest","validExts",defaultExt);

and then repeat the getvalue line, it produces the expected result.

Is this a bug or "you just can't do that". The line from the help makes
it seem that it should work.

Jim
 
copied from MSDN help on Registry class:

string[] tArray = (string[])Registry.GetValue(keyName,"TestArray",
                newstring[] {"Default if TestArray does not exist."});

Here's my code:

string[] defaultExt = {".mp4",".avi"};
string[] validExts;
validExts = (string[])Registry.GetValue("myTest","validExts",defaultExt);

if the registry is empty, this always returns null. I'm expecting
{".mp4",".avi"}.

if I make the next line:

if (validExts = null) Registry.SetValue("myTest","validExts",defaultExt);

and then repeat the getvalue line, it produces the expected result.

Is this a bug or "you just can't do that". The line from the help makes
it seem that it should work.

Jim

From MSDN:
----------
Return Value
Type: System..::.Object
a null reference (Nothing in Visual Basic) if the subkey specified by
keyName does not exist; otherwise, the value associated with
valueName, or defaultValue if valueName is not found.
 
NvrBst said:
copied from MSDN help on Registry class:

string[] tArray = (string[])Registry.GetValue(keyName,"TestArray",
newstring[] {"Default if TestArray does not exist."});

Here's my code:

string[] defaultExt = {".mp4",".avi"};
string[] validExts;
validExts = (string[])Registry.GetValue("myTest","validExts",defaultExt);

if the registry is empty, this always returns null. I'm expecting
{".mp4",".avi"}.

if I make the next line:

if (validExts = null) Registry.SetValue("myTest","validExts",defaultExt);

and then repeat the getvalue line, it produces the expected result.

Is this a bug or "you just can't do that". The line from the help makes
it seem that it should work.

Jim

From MSDN:
----------
Return Value
Type: System..::.Object
a null reference (Nothing in Visual Basic) if the subkey specified by
keyName does not exist; otherwise, the value associated with
valueName, or defaultValue if valueName is not found.

Hmm, could be. It is the first line of registry reads. I'll have to
rearrange the order and see if it makes a difference.

Jim
 
Back
Top