C#Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I just wanted to let you know that I have created a generic approach to this problem that allows you to specify the type you want the resulting array or list to be. A blog post describing this solution can be found here.
I do apologize for posting in the incorrect forum. I didn't notice it was a C# 1.0 forum.
You propose and interesting suggestion. The only thing about the ConvertAll method is that it requires you to write a delegate that does the conversion from one type to another. First, that could separate the code more so you have to go looking for the converter logic (then again since we are out of the C# 1.0 realm, you could use an anonymous delegate which would place the code inline). Second, if you really want to make it generic like I did, you still have to use the Convert.ChangeType method or something similar as you can't directly cast a string to a decimal, float, etc and obviously you can throw in a XXX.Parse as that would be binding to a given type.
While ConvertAll is a great use of the framework, is there any real benefit of using it over what I did? Maybe this isn't the greatest place to continue this discussion but I would be interested in your feedback.
I guess it depends on how often you are going to be doing splits. Personally the code you have written to do it the generic way is great, but is much more code to write than simply doing it in line like this:
True true. Just like everything else in life, its conditional! You are right, if my goal wasn't re-usability and broad application the method you presented is a great one line solution. I think I will amend my post to include the solution you presented, citing you of course.