0

I have a string array as shown below: How do I write each one of them to the console? Below is the code from my c# program: From the below code I have to write all the cats to the console

using (RegistryKey ic = clsidKey.OpenSubKey("Implemented Categories"))
                        {
                            string[] cats = ic.GetSubKeyNames();

}

4 Answers 4

7

Don't you just do this?

foreach (string cat in cats) {
    Console.WriteLine(cat);
}
Sign up to request clarification or add additional context in comments.

Comments

5

in Linq style

Array.ForEach(cats, Console.WriteLine);

1 Comment

You can also use Array.ForEach(cats, System.Console.WriteLine); as System.Console.WriteLine meets the Action<string> delegate signature
3

Try this:

foreach(string cat in cats)
{
    Console.WriteLine(cat);
}

Comments

0

Or even more specifically:

foreach(string cat in cats)
{
    Console.Out.WriteLine(cat);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.