Click here to Skip to main content
15,910,872 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delete a directory Pin
MicealG17-May-07 4:57
MicealG17-May-07 4:57 
GeneralRe: Delete a directory Pin
jayart17-May-07 5:12
jayart17-May-07 5:12 
GeneralRe: Delete a directory Pin
MicealG17-May-07 5:18
MicealG17-May-07 5:18 
GeneralRe: Delete a directory Pin
MicealG17-May-07 5:22
MicealG17-May-07 5:22 
AnswerRe: Delete a directory Pin
Jimmanuel17-May-07 5:18
Jimmanuel17-May-07 5:18 
Questionhow to connect to http servers/My website and download the files Pin
pashitech17-May-07 4:16
pashitech17-May-07 4:16 
AnswerRe: how to connect to http servers/My website and download the files Pin
led mike17-May-07 4:42
led mike17-May-07 4:42 
GeneralRe: how to connect to http servers/My website and download the files Pin
pashitech17-May-07 5:03
pashitech17-May-07 5:03 
GeneralRe: how to connect to http servers/My website and download the files Pin
led mike17-May-07 6:16
led mike17-May-07 6:16 
QuestionStringBuilder and ASCII. [modified] Pin
Russell Jones17-May-07 3:20
Russell Jones17-May-07 3:20 
AnswerRe: StringBuilder and ASCII. Pin
led mike17-May-07 4:54
led mike17-May-07 4:54 
GeneralRe: StringBuilder and ASCII. Pin
Russell Jones17-May-07 5:32
Russell Jones17-May-07 5:32 
QuestionNew in .NET 2.0 Pin
Blumen17-May-07 3:20
Blumen17-May-07 3:20 
AnswerRe: New in .NET 2.0 Pin
Christian Graus17-May-07 3:22
protectorChristian Graus17-May-07 3:22 
GeneralRe: New in .NET 2.0 Pin
Blumen17-May-07 3:27
Blumen17-May-07 3:27 
GeneralRe: New in .NET 2.0 Pin
Christian Graus17-May-07 3:30
protectorChristian Graus17-May-07 3:30 
GeneralRe: New in .NET 2.0 Pin
Judah Gabriel Himango17-May-07 5:18
sponsorJudah Gabriel Himango17-May-07 5:18 
AnswerRe: New in .NET 2.0 Pin
Russell Jones17-May-07 3:52
Russell Jones17-May-07 3:52 
AnswerRe: New in .NET 2.0 Pin
Nissim Salomon17-May-07 5:24
Nissim Salomon17-May-07 5:24 
Questionhow to get textbox control? Pin
newtocsharp17-May-07 3:14
newtocsharp17-May-07 3:14 
AnswerRe: how to get textbox control? Pin
Judah Gabriel Himango17-May-07 5:47
sponsorJudah Gabriel Himango17-May-07 5:47 
QuestionHelp needed to convert function to a generic function Pin
Jim Taylor17-May-07 3:11
Jim Taylor17-May-07 3:11 
I have a function that a function that takes in a string like "1,2,3,4324,3423". I need to return an array of a type that I specifiy using that string so in this case it would return an array of ints or shorts etc like { 1, 2, 3, 4324, 3423 }.
The code I wrote to do this is below ...
   <br />
usage: int[] myInts = (int[])CommaSeparatedStringToIEnumerable("1,2,3,4324,3423", typeof(int));     <br />
<br />
public static IEnumerable CommaSeparatedStringToIEnumerable(string str, <br />
Type destinationType)<br />
        {<br />
            List<string> list = new List<string>(str.Split(','));<br />
            list.RemoveAll(delegate(string s) { return s.Trim().Length == 0 ;});<br />
            IEnumerable output;<br />
            if (destinationType == typeof(int))<br />
                output = list.ConvertAll<int>(delegate(string s) { return Convert.ToInt32(s.Trim()); }).ToArray();<br />
            else if (destinationType == typeof(short))<br />
                output = list.ConvertAll<short>(delegate(string s) { return Convert.ToInt16(s.Trim()); }).ToArray();<br />
            else if (destinationType == typeof(byte))<br />
                output = list.ConvertAll<byte>(delegate(string s) { return Convert.ToByte(s.Trim()); }).ToArray();<br />
            else if (destinationType == typeof(bool))<br />
                output = list.ConvertAll<bool>(delegate(string s) { return Convert.ToBoolean(s.Trim()); }).ToArray();<br />
            else if (destinationType == typeof(string))<br />
                output = list.ConvertAll<string>(delegate(string s) { return s.Trim(); }).ToArray();<br />
            else<br />
                throw new NotSupportedException("Type not supported.");<br />
            return output;<br />
        }

I can't help thinking that this could be acheived using a generic function like
public static T[] CommaSeparatedStringToArray(string str)
but I've been round the houses trying to do this. Any ideas, good articles would be appreciated.



Jim

AnswerRe: Help needed to convert function to a generic function Pin
Not Active17-May-07 4:12
mentorNot Active17-May-07 4:12 
GeneralRe: Help needed to convert function to a generic function Pin
Jim Taylor17-May-07 4:59
Jim Taylor17-May-07 4:59 
AnswerRe: Help needed to convert function to a generic function Pin
Judah Gabriel Himango17-May-07 5:11
sponsorJudah Gabriel Himango17-May-07 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.