acadia
acadia

Reputation: 1657

Read from Array in C#

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();

}

Upvotes: 0

Views: 491

Answers (4)

Jeremy Roberts
Jeremy Roberts

Reputation: 1208

in Linq style

Array.ForEach(cats, Console.WriteLine);

Upvotes: 5

Clay Fowler
Clay Fowler

Reputation: 2078

Or even more specifically:

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

Upvotes: 0

Dan Tao
Dan Tao

Reputation: 128317

Don't you just do this?

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

Upvotes: 7

Matthew Jones
Matthew Jones

Reputation: 26190

Try this:

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

Upvotes: 3

Related Questions