How to convert c# linq code to vb.net code ?

Hi,

I found useful  code that converts System.Array to String, but i couldn't succeed to implement to my vb.net application.

Any help would be great.

Thanks.

string[] foo = someObjectArray.OfType<object>().Select(o => o.ToString()).ToArray();

Open in new window

HakanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
>>...code that converts System.Array to String

Wrong.  That code gives an array of strings, not a string.
Chinmay PatelChief Technology NinjaCommented:
Hi Hakan,

Please give this one a try:
someObjectArray.OfType(Of Object)().[Select](Function(o) o.ToString()).ToArray()

Open in new window


Regards,
Chinmay.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Commented:
If this truly is an array, then the OfType call is really extraneous here--having the Select alone should be sufficient.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

HakanAuthor Commented:
thanks for your contributions and advice. I'm really appreciate.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
Agreed.  It could simply be:
Dim foo As String() = someObjectArray.Select(Function(s) s.ToString).ToArray

Open in new window


You could also use Array.ConvertAll():
Dim foo As String() = Array.ConvertAll(someObjectArray, Function(s) s.ToString)

Open in new window

AndyAinscowFreelance programmer / ConsultantCommented:
The big question is if one string is required as the result.  Note how the question was worded - it converts array to string

eg.
4 objects in an array each contain in order one of the following words "this" "is" "a" "string"
After running the code one has an array of four strings "this" "is" "a" "string"
The result is NOT one string "this is a string"
HakanAuthor Commented:
@Mike your code is give an error on visual studio editor. It says "Select" is not member of array.
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Commented:
Make sure:

Imports System.Linq

...is at the top of your file.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.