cannot implicitly convert type system.collections.generic.IEnumerable<string> to string[]

Trying to solve and getting to following error

public String[] Any()
{                            
    var lastSixMonths = Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6)).Select(date => date.ToString("MM/yyyy"));

    return lastSixMonths;
}

Since the lastSixMonths is the IEnumerable<string> and you are expecting an array, try this:

return lastSixMonths.ToArray();

I have also created .NET Fiddle to show how you could print the string[].

[Solved] Cannot implicitly convert type 'System.Collections.Generic , Use var and don't create a list at all. You need to call ToList at the end of your Select in order to get back a list, instead of an IEnumerable. Cannot implicitly convert type 'System.Collection.Generic.IEnumerable<string>' to 'string' and. Cannot implicitly convert type 'System.Collection.Generic.IEnumerable<System.Collection.Generic.IEnumerable.IEnumerable<string>' to 'string'. I tried casting to ToString() but it was worthless, no errors shows but data was replaced with system messages.


This way:

public String[] Any()
{   
    return Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6)).Select(date => date.ToString("MM/yyyy")).ToArray();
}

Why didn't it work?

Linq's Select returns an IEnumerable with filtering, sorting etc, instructions.

It's up to you, to decide what to retrieve, if a single element FirstOrDefault or more than one element like ToList , ToArray , ToDictionary etc..

Cannot implicitly convert type 'System.Collections.Generic.List , applicantdata is IEnumerable<APPLICANT> , in your select statement you are selecting anonymous type object using new keyword, that is why you can't convert it to IEnumerable<APPLICANT> . You have to create a temporay class with your properties as in select statement and return IEnumerable of that class. Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<DataModel.Shop>' to 'System.Collections.ObjectModel.ObservableCollection<DataModel.Shop>'. So I am using this code as a solution instead, but seems not the best way. I would like to know how to filter ObservableCollection with .Where in my method.


Your problem: Your .Select() call does return an IEnumerable that you have to explicit convert into an array.

An improvement: There was no need to make two .Select() calls one after the other, you could have made with just one call.

public String[] Any()
{                            
    IEnumerable<string> lastSixMonths = Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6).ToString("MM/yyyy"));
    // Now we convert it into an array.
    string[] returned = lastSixMonths.ToArray();
    return returned;
}

Cannot implicitly convert type 'System.Collections.Generic , IEnumerable<xxx>>' to 'System.Collections.Generic.List<xxx>. I am getting the following error. I googled it for more than a day but I cant find  Cannot implicitly convert type 'System.Web.Http.Results.NotFoundResult' to 'System.Collections.Generic.IEnumerable<…>' 2 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable Cast error


This should do it:

public String[] Any()
{                            
    IEnumerable<String> lastSixMonths = Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6)).Select(date => date.ToString("MM/yyyy"));
    return lastSixMonths.ToArray();
}

Cannot implicitly convert type - List is listed as IEnumerable?., Cannot implicitly convert type 'System.Collections.Generic.List< >' to 'System. ViewModels.InvoiceMaster>' to 'System.Collections.Generic.IList<ICSNew. uses the fact that an IEnumerable<InvoiceMaster> is an IEnumerable<InvoiceHD​>  Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<anonymoustype#1>' to 'System.Collections.Generic.List<tools.businessobjects.eventgroup>'. An explicit conversion exists (are you missing a cast?)


public String[] Any()
{   
    return Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(i - 6)).Select(date => date.ToString("MM/yyyy")).ToArray();
}

What needs to be understood

Understand the requirement, fetching 6 months of data from the database using LINQ will provide us a collection of data or multiple rows. So if we want we can limit it by giving condition and using .FirstorDefault or if we need an array or in the list format we can use .ToList or .ToArray.

Cannot implicitly convert type 'System.Collections.Generic , Just change this: Select(x => new { x.Access }). To This: Select(x => x.Access). The reason is, new makes your query to return an IEnumerable  I want to reverse some chars but I get the following error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<int[]>' to 'int[][]'.


cannot implicitly convert type to system.collection.generic., cannot implicitly convert type to system.collection.generic. Dec 3 2013 4:20 public IEnumerable<subCategory> subCategoriesList { get; set; }. Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<T>' to 'Microsoft.AspNetCore.Mvc.ActionResult<System.Collections.Generic.IEnumerable<T>> #8061 fspataro opened this issue Jul 12, 2018 · 2 comments