thank you. so far C# is much more difficult than i image. its too bad i could
not just cast the
object o = tempKey.GetValue(valueName);
string stringValue = o as string;
as an array up front thus removing more code than i wanted. i'm adding the
changes so you can comment if there is any better way to handle it since i'm
not comfortable with C#.
==
foreach(string valueName in tempKey.GetValueNames())
{
object o = tempKey.GetValue(valueName);
string stringValue = o as string;
//test for string
if (stringValue != null)
{
//if string print
Console.WriteLine("{0,-8}: {1} \t\t\t{2}", valueName,
tempKey.GetValue(valueName).ToString(),
tempKey.GetValue(valueName).GetType());
}
else
{
//test for array again
string[] stringArray = o as string[];
int i= 0;
if (stringArray != null)
{
//if an array iterate and print elements!
System.Collections.IEnumerator myEnumerator = stringArray.GetEnumerator();
Console.WriteLine("{0,-8}: ", valueName);
Console.WriteLine( "\tis an Array containing the following values:" );
while (( myEnumerator.MoveNext() ) && ( myEnumerator.Current != null ))
Console.WriteLine( "\t\t[{0}] {1}", i++, myEnumerator.Current );
}
else
{
//if not string or an array print as usual
Console.WriteLine("{0,-8}: {1} \t\t\t{2}", valueName,
tempKey.GetValue(valueName).ToString(),
tempKey.GetValue(valueName).GetType());
}
}
Console.WriteLine("{0,-8}: {1} {2}", valueName,
tempKey.GetValue(valueName).ToString(),
tempKey.GetValue(valueName).GetType()); */
}//foreach(string valueName in tempKey.GetValueNames())
thank you for help on this any revisions would help greatly.
==
"Jon Skeet [C# MVP]" wrote:
auldh <au***@discussions.microsoft.com> wrote: Jon, i'm a novice to C# i have taken most of this code from MSDN Registry
Class section. i'm trying out C# over my VB6.0.
i believe i understand what you are saying but i think the problem is
knowing when to look at the value as an array. in most cases the exiting line
of code
foreach(string valueName in tempKey.GetValueNames())
{
Console.WriteLine("{0,-8}: {1} {2}", valueName,
tempKey.GetValue(valueName).ToString(),
tempKey.GetValue(valueName).GetType());
}//foreach(string valueName in tempKey.GetValueNames())
gives the output correctly. in VB6.0 i used a class the recoginized the when
to expand the data as an array. in the MSDN i don't see how it is done. from
what you have written i not sure it is easy for me to do read.
If you get the value as an object, you can test its type:
object o = tempKey.GetValue(valueName);
string stringValue = o as string;
if (stringValue != null)
{
// it's a string
}
else
{
string[] stringArray = o as string[];
if (stringArray != null)
{
...
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too