Datkros
Datkros

Reputation: 21

The best overloaded method match for System.Collection.. has some invalid arguments

I have a problem when writing my app, I want to create an Data source that gives me the information of the titles, but it gives me this error;

"The best overloaded method match for 'Systems.Collections.ObjectModel.ObservableCollection.ObservableCollection(System.Collections.Generic.IEnumerable)' has some invalid arguments.

Here is my code;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App1
{
class DataSourceTitulos
{
    public ObservableCollection<Titulos> ListaTitulos { get; set; }

    public DataSourceTitulos()
    {
        Initialize();
    }
    private int TraerInfoDesdeDatos;

    public void Initialize()
    {
        var listaFull = TraerInfoDesdeDatos;
        ListaTitulos = new ObservableCollection<Titulos>(listaFull);
    }
  }
}

I'd appreciate your help.

Upvotes: 1

Views: 1467

Answers (3)

IllusiveBrian
IllusiveBrian

Reputation: 3224

Unless I'm missing something, TraerInfoDesdeDatos is never given a value before being used. As well, ObservableCollection has only 3 constructors, one of which is empty and the other two take either an IEnumerable or List. None of them take an int. If you are trying to set the size of the collection, it does not appear that there is a method to do this, but the size is dynamic so you can just add your elements individually anyway.

Upvotes: 0

Servy
Servy

Reputation: 203847

ObservableCollection doesn't have a constructor that takes an int, which is what you're passing in. It only has constructors that take no arguments, a List, or an IEnumerable of items.

Upvotes: 1

Daniel Gabriel
Daniel Gabriel

Reputation: 3985

Remove the listFull parameter from your new ObservableCollection<Titulos>(listFull) call.

Upvotes: 1

Related Questions