Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to adjust "is a type but is used like a variable"?

I'm trying to generate some code in a web service. But it's returning 2 errors:

1) List is a type but is used like a variable

2) No overload for method 'Customer' takes '3 arguments'

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class wstest : System.Web.Services.WebService
    {

        [WebMethod]
        public List<Customer> GetList()
        {
            List<Customer> li = List<Customer>();
            li.Add(new Customer("yusuf", "karatoprak", "123456"));
            return li;
        }
    }

    public class Customer
    {
        private string name;
        private string surname;
        private string number;

        public string Name { get { return name; } set { name = value; } }
        public string SurName { get { return surname; } set { surname = value; } }
        public string Number { get { return number; } set { number = value; } }
    }

How can i adjust above error?

like image 783
ALEXALEXIYEV Avatar asked Jun 01 '09 11:06

ALEXALEXIYEV


1 Answers

The problem is at the line

List<Customer> li = List<Customer>();

you need to add "new"

List<Customer> li = new List<Customer>();

Additionally for the next line should be:

li.Add(new Customer{Name="yusuf", SurName="karatoprak", Number="123456"});

EDIT: If you are using VS2005, then you have to create a new constructor that takes the 3 parameters.

public Customer(string name, string surname, string number)
{
     this.name = name;
     this.surname = surname;
     this.number = number;
}
like image 141
Jose Basilio Avatar answered Oct 14 '22 22:10

Jose Basilio