Click here to Skip to main content
15,907,392 members
Home / Discussions / C#
   

C#

 
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 
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 
GeneralRe: Help needed to convert function to a generic function Pin
Jim Taylor17-May-07 5:34
Jim Taylor17-May-07 5:34 
GeneralRe: Help needed to convert function to a generic function Pin
Not Active17-May-07 6:20
mentorNot Active17-May-07 6:20 
GeneralRe: Help needed to convert function to a generic function Pin
Judah Gabriel Himango17-May-07 7:15
sponsorJudah Gabriel Himango17-May-07 7:15 
AnswerRe: Help needed to convert function to a generic function Pin
Nissim Salomon20-May-07 0:19
Nissim Salomon20-May-07 0:19 
Hi
the following code use reflection in order to convert string items to value
types using the static function TryParse.


using System;
using System.Collections.Generic;
using System.Reflection;

namespace CMDLineTest
{
class Program
{
static List<t> CommaSeparatedStringToIEnumerable<t>(string s)
{
List<t> values = new List<t>();

Type targetConversionType = typeof(T);

if (targetConversionType.IsValueType)
{
Type targetConversionTypeOutParamType = Type.GetType(targetConversionType.FullName + @"&");

if(targetConversionTypeOutParamType == null)
throw new Exception("");

MethodInfo tryParseMethodInfo = targetConversionType.GetMethod("TryParse", new Type[] { typeof(string), targetConversionTypeOutParamType });

if(tryParseMethodInfo != null)
{
string[] stringsToConvert = s.Split(',');

T item = default(T);

object[] methodParams = new object[2];

foreach (string str in stringsToConvert)
{
methodParams[0] = str;
methodParams[1] = item;

if (((bool)tryParseMethodInfo.Invoke(null, methodParams)) == true)
values.Add((T)methodParams[1]);

}
}
}

return values;
}

static void Main(string[] args)
{
List<int> intList = CommaSeparatedStringToIEnumerable<int>("1,2,3,4,5");

foreach (int item in intList)
Console.WriteLine(item);
}
}
}
QuestionWhat are the Books on C#..?? Pin
IamPoojaa17-May-07 2:39
IamPoojaa17-May-07 2:39 
AnswerRe: What are the Books on C#..?? Pin
Sathesh Sakthivel17-May-07 2:51
Sathesh Sakthivel17-May-07 2:51 
GeneralRe: What are the Books on C#..?? Pin
IamPoojaa17-May-07 3:08
IamPoojaa17-May-07 3:08 

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.