Cannot implicitly convert type "System.Collection.Generic.List ....

I have created a GeneralSetupCompanyView Model inside my GetViewModel but I'm getting the following error when I assign my property CountryOption to the value CountryOptions = GetViewModelCountryOptions(vm.SelectedCountry).  
This GeneralSetupCompanyView is in a different namespace than the namespace ServiceAssistant.Areas.Parameters.Controllers.

My question is do I need to move my Service.Assistant.Model.Service.Picker.Item to the namespace where my GeneralSetupCompanyreside  or how should I correct this line of code:
CountryOptions = GetViewModelCountryOptions(vm.SelectedCountry),

Cannot implicitly convert type "System.Collection.Generic.List<Service.Assistant.Model.Service.Picker.Item>'to 'System.Collections.Generic.List<Systems.Models.SelectPicker.Item>'

namespace ServiceAssistant.Areas.Parameters.Controllers
{
    public class CompanyGeneralSetupController : BaseController
    {
        // GET: Parameters/CompanyGeneralSetup
        public ActionResult Index()
        {
            var employee = LoggedInUser;
            canView = null;
            if (!canView)
            {
                return RedirectToAction("Index", "Parameters", new { area = "Parameters" });
            }

            var viewModel = GetViewModel(employee);
            return View(viewModel);
        }

        private GeneralSetupCompanyViewModel GetViewModel(Employee employee)
        {
          
            var parameters = ParameterConfigurationService.GetParameters();

            bool hasRights = value1;
            bool hasEditRights = value2;
                      
           GeneralSetupCompanyViewModel vm = new GeneralSetupCompanyViewModel
           {
            NoRights = !hasRights,
            hasEditRights = hasEditRights,
       
           CountryOptions = GetViewModelCountryOptions(vm.SelectedCountry),    //       <====  HERE
            };
           return vm;
        }

        private List<Item> GetViewModelCountryOptions(char? selectedCountry)
        {
            var items = new List<Item>();
            var country = CountryCodes.Country.UnitedStates;
            items.Add(new Item
            {
                Text = country.GetText(),
                Value = country.GetCode().ToString(),
                IsSelected = selectedCountry == country.GetCode()
            });
            return items;
        }

Open in new window

yguyon28Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
You could explicitly cast it
change
CountryOptions = GetViewModelCountryOptions(vm.SelectedCountry),
to
CountryOptions = GetViewModelCountryOptions((XXX)vm.SelectedCountry),  where XXX is the class including namespace of the object
0
yguyon28Author Commented:
I had an issue with my casting, could I get a better example if it's possible. Thank you
0
AndyAinscowFreelance programmer / ConsultantCommented:
What issue?
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

yguyon28Author Commented:
My problem is to actually write the syntax for it. I'm not sure what class or namespace to use to correct this. Sorry if its such an easy question..
0
AndyAinscowFreelance programmer / ConsultantCommented:
If you have a class called Foo in a namespace XYZ then you use XYZ.Foo

I don't like just making something you can copy/paste - it helps you understand if you have to do the final step yourself.
0
Piotr StrycharzSoftware/web developerCommented:
Direct convertion is not supported in c#. You may however use List<T>.ConvertAll... method to convert list of items to list ot other item type. Sth like that:

CountryOptions = GetViewModelCountryOptions(vm.SelectedCountry).ConvertAll<Systems.Models.SelectPicker.Item>(each => convert(each));

private Systems.Models.SelectPicker.Item convert(Service.Assistant.Model.Service.Picker.Item item) {
 // you must write code to convert input value to Systems.Models.SelectPicker.Item
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
@Piotr
Either you are talking about something completely different or you are wrong.

SNAG-0014.bmp
Casting is allowed - see the sizes of the objects after casting them to a different types.
0
yguyon28Author Commented:
Thank you for the help..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.