无法将方法组分配给ASP.NET,LINQ,C#中隐式型的本地变量[英] Cannot assign method group to an implicitly-typed local variable in asp.net,linq,c#

本文是小编为大家收集整理的关于无法将方法组分配给ASP.NET,LINQ,C#中隐式型的本地变量的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

public void selectqueryasso()
    {
        CustomerOrderResult cso=new CustomerOrderResult();
        var a = (from as1 in ds.orders
                   from as2 in ds.order_details
                   where (as1.oid == as2.oid)
                   orderby as1.pname
                   select new CustomerOrderResult 
                   {
                      oid = Convert.ToInt32(as1.oid),
                      cmny =as1.cmny,
                      ocountry=as1.ocountry,
                      pname=as1.pname,
                      price= Convert.ToString(as1.price),
                      orderno= Convert.ToString(as1.orderno),
                      saltitle=as1.saltitle
                   }).ToList<CustomerOrderResult>;

        GridView1.DataSource = a;
        GridView1.DataBind();
    }

无法将方法分配给隐式型的本地变量 无法将方法组分配给隐式型的本地变量 无法将方法组分配给隐式型的本地变量

推荐答案

您实际上没有调用ToList()方法,而是在那里缺少括号:

public void selectqueryasso()
{
    CustomerOrderResult cso=new CustomerOrderResult();
    var a = (from as1 in ds.orders
               from as2 in ds.order_details
               where (as1.oid == as2.oid)
               orderby as1.pname
               select new CustomerOrderResult 
               {
                  oid = Convert.ToInt32(as1.oid),
                  cmny =as1.cmny,
                  ocountry=as1.ocountry,
                  pname=as1.pname,
                  price= Convert.ToString(as1.price),
                  orderno= Convert.ToString(as1.orderno),
                  saltitle=as1.saltitle
               }).ToList<CustomerOrderResult>();

    GridView1.DataSource = a;
    GridView1.DataBind();
}

本文地址:https://www.itbaoku.cn/post/1556839.html

问题描述

public void selectqueryasso()
    {
        CustomerOrderResult cso=new CustomerOrderResult();
        var a = (from as1 in ds.orders
                   from as2 in ds.order_details
                   where (as1.oid == as2.oid)
                   orderby as1.pname
                   select new CustomerOrderResult 
                   {
                      oid = Convert.ToInt32(as1.oid),
                      cmny =as1.cmny,
                      ocountry=as1.ocountry,
                      pname=as1.pname,
                      price= Convert.ToString(as1.price),
                      orderno= Convert.ToString(as1.orderno),
                      saltitle=as1.saltitle
                   }).ToList<CustomerOrderResult>;

        GridView1.DataSource = a;
        GridView1.DataBind();
    }

Cannot assign method group to an implicitly-typed local variable Cannot assign method group to an implicitly-typed local variable Cannot assign method group to an implicitly-typed local variable

推荐答案

You are not actually calling the ToList() method, you are missing the parentheses there:

public void selectqueryasso()
{
    CustomerOrderResult cso=new CustomerOrderResult();
    var a = (from as1 in ds.orders
               from as2 in ds.order_details
               where (as1.oid == as2.oid)
               orderby as1.pname
               select new CustomerOrderResult 
               {
                  oid = Convert.ToInt32(as1.oid),
                  cmny =as1.cmny,
                  ocountry=as1.ocountry,
                  pname=as1.pname,
                  price= Convert.ToString(as1.price),
                  orderno= Convert.ToString(as1.orderno),
                  saltitle=as1.saltitle
               }).ToList<CustomerOrderResult>();

    GridView1.DataSource = a;
    GridView1.DataBind();
}