Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting KeysCollection to string[]

0 views
Skip to first unread message

Candan Akyol

unread,
Apr 5, 2002, 8:47:59 AM4/5/02
to
Hi all,

Is there a good method to convert the object of type
NameObjectCollectionBase.KeysCollection to an array of string without
enumerating? Or, let define the problem in a different way. I have an
instance of KeysCollection class, and I want to join the elements of this
collection into a single string, seperated by commas. Any ideas? Thanks in
advance.


Candan Akyol

unread,
Apr 5, 2002, 9:10:37 AM4/5/02
to
Oops.. Got it.. BaseGetAllKeys() method does it.. Sorry :)

"Candan Akyol" <cak...@digilane.com> wrote in message
news:uqFBBiK3BHA.2680@tkmsftngp04...

Nicholas Paldino [.NET MVP]

unread,
Apr 5, 2002, 9:11:16 AM4/5/02
to
Candan,

You are going to have to do this manually. And easy way to do this
would be:

// The StringBuilder that will be used to create the list.
StringBuilder pobjBuilder = new StringBuilder();

// Cycle through the objects. Assume pobjCollection is the KeysCollection.
foreach (string pstrString in pobjCollection)
{
// Append the string.
pobjBuilder.Append(pstrString);

// Append a comma.
pobjBuilder.Append(',');
}

// If there is anything in the string, then that means one item
// was placed in the string, along with a comma. Take off the last comma
// if this is the case.
if (pobjBuilder.Length > 0)
// Trim off the last comma.
pobjBuilder.Remove(pobjBuilder.Length - 1, 1);

// Get the string.
string pstrString = pobjBuilder.ToString();

Hope this helps.


--
- Nicholas Paldino [.NET MVP]
- nicholas...@exisconsulting.com

"Candan Akyol" <cak...@digilane.com> wrote in message
news:uqFBBiK3BHA.2680@tkmsftngp04...

Candan Akyol

unread,
Apr 5, 2002, 9:16:55 AM4/5/02
to
Thanks for the answer Nicholas, I was coding a class that inherited from
NameObjectCollectionBase, so I can reach the base.BaseGetAllKeys() method
and use String.Join(",", base.BaseGetAllKeys())

"Nicholas Paldino [.NET MVP]" <nicholas...@exisconsulting.com> wrote in
message news:uvrZFvK3BHA.2228@tkmsftngp07...

0 new messages