Click here to Skip to main content
16,005,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m using web config file and in <appsetting> tag,<add key="i" value="{">


now in cs file i want value of i[0] n i[1] i.e; int type

int[] i=configurationsetting.appsettings["i"].split(',');

but this give the error i.e; can not implicitly convert the int to int[].
Posted
Updated 10-Oct-10 18:49pm
v3

1 solution

int[] i=configurationsetting.appsettings["i"].split(',');

The use of the Split method implies configurationsetting.appsettings["i"] is a string.
The Split method returns an array of strings.
So you would need to loop through each string and convert it to an int, then store those in an array if that is how you want to access them.

C#
string[] strings = configurationsetting.appsettings["i"].Split(',');
int[] numbers = new int[strings.Length];
for (int i = 0; i < strings.Length; i++)
    {
    int.TryParse(strings[i], out numbers[i]);
    }
 
Share this answer
 
Comments
Hiren solanki 11-Oct-10 1:14am    
good solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900