I have a class Helper
with 2 methods
public static List<string> GetCountryName()
{
List<string> CountryName = new List<string>();
using (var sr = new StreamReader(@"Country.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
int index = line.LastIndexOf(" ");
CountryName.Add(line.Substring(0, index));
}
}
return CountryName;
}
public static List<string> GetCountryCode()
{
List<string> CountryCode = new List<string>();
using (var sr = new StreamReader(@"Country.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
int index = line.LastIndexOf(" ");
CountryCode.Add(line.Substring(index + 1));
}
}
return CountryCode;
}
I bind these return values with my WPF ComboBox as follows
ddlCountryName.ItemsSource = Helper.GetCountryName();
ddlCountryCode.ItemsSource = Helper.GetCountryCode();
I wanted to return these List in a single method and went through these links
https://stackoverflow.com/a/10278769
After going through it I tries like this but could not able to make it properly from line no-3 Tuple<List<string>> CountryName = new Tuple<List<string>>
public static Tuple<List<string>,List<string>> GetAllData()
{
Tuple<List<string>> CountryName = new Tuple<List<string>>
List<string> CountryCode = new List<string>();
using (var sr = new StreamReader(@"Country.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
int index = line.LastIndexOf(" ");
CountryName.Add(line.Substring(0, index));
CountryCode.Add(line.Substring(index + 1));
}
}
return CountryName;
return CountryCode;
}
Please help me to return List item wise and bind in the ItemsSource
as per the below code
ddlCountryName.ItemsSource = Helper.GetCountryName();