如何在c#中返回一个字符串和一个元素列表?

Him*_*ani 1 c#

有没有办法将字符串参数和列表返回给c#中的方法?

List<cCountry> countries = new List<cCountry>();
            countries = GetCountries(userProfile.Country);


     private List<cCountry> GetCountries(string p)
            {
                inputCollection = new cDTOCollection<cDTOBase>();
                outputCollection = new cDTOCollection<cDTOBase>();
                outputCollection = UpdateProfileBizobj.ProcessRequest(ActionConstants.ActionGetCountriesList, null);
                List<cCountry> countries = new List<cCountry>();
                cDTOSingleValue SelectedCountryID = new cDTOSingleValue();
                foreach (cDTOCountry countryItem in outputCollection)
                {
                    if (p == countryItem.CountryName)
                        SelectedCountryID.Id = countryItem.CountryID;

                    countries.Add(Mapper.Map<cDTOCountry, cCountry>(countryItem));
                }
                countries.Remove(countries[0]);
                return countries;
            }
Run Code Online (Sandbox Code Playgroud)

就像上面的方法一样,我需要返回一个参数SelectedCountryID以及国家列表.有没有办法返回两者?

use*_*620 7

填充并返回一个对象.

public class ReturnObject
{
    public List<cCountry> Countries { get; set; }
    public guid SelectedCountryID { get; set; } // don't think you defined what type SelectedCountryID is in your question
}
Run Code Online (Sandbox Code Playgroud)

但是如果你发现自己需要返回超过1个东西,那么这可能表明你的方法做得太多而且应该重构.

为什么不能重用您发送给方法的值?