如何将返回类型列表调用到另一个列表方法 [英] How to call return type list to another list method

查看:80
本文介绍了如何将返回类型列表调用到另一个列表方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在asp.net中创建自动文本完成文本框



我尝试过这种方法,不使用webservices





这是我的方法



I have to create auto text completion textbox in asp.net

I have tried this method that without using webservices


This is my method

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] GetProductList(string prefixText, int count)
{
    // Get the Products From Data Source. Change this method to use Database
    List<string> empList = GetEmpNames();

    // Find All Matching Products
    var list = from p in empList
               where p.Contains(prefixText)
               select p;

    //Convert to Array as We need to return Array
    string[] prefixTextArray = list.ToArray<string>();

    //Return Selected Products
    return prefixTextArray;
}

private  List<string> GetEmpNames()
{

    Entities objEntity=new Entities();
    var empList = (from empDetails in objEntity.HCM_EMPLOYEE_DETAILS
                   select empDetails).ToList();
    return empList;

}









colud you请告诉我如何将var数据返回到list方法我的意图是下面的方法我将调用上面的方法。



所以请帮助我..





colud you please tell me how to return var data to list method my intention is below method i will call to above method.

so please help me..

推荐答案

将方法设为静态。

make the method as static.
private static List<string> GetEmpNames()


当您执行Linq to Objects查询时,它将返回IEnumerable< Student>类型,您可以使用< a href =http://msdn.microsoft.com/en-us/library/bb342261.aspx> ToList() [ ^ ]创建List< T>的方法来自IEnumerable< T>:



When you do the Linq to Objects query, it will return you the type IEnumerable<Student>, you can use the ToList()[^] method to create a List<T> from an IEnumerable<T>:

var selected = from s in studentCollection
                           select s;

List<Student> selectedCollection = selected.ToList();



这可能会有所帮助。


This may help.


这篇关于如何将返回类型列表调用到另一个列表方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆