Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 字符串数组类型方法返回类型错误 公共字符串[][]GetAllItems() { FoodCityData.ShoppingBuddyEntities fdContext=新的FoodCityData.ShoppingBuddyEntities(); 可查询查询= 来自fdContext.Item中的c 选择c; List AllfNames=Query.ToList(); int arrayZise=AllfNames.Count; 字符串[,]xx=新字符串[arrayZise,2]; int i=0; int j=0; foreach(所有名称中的项目x) { xx[i,0]=x.ItemName.ToString(); xx[i,1]=x.ItemPrice.ToString(); i++; } return xx[2,2];//如何编写返回类型? }_C#_Arrays_String - Fatal编程技术网

C# 字符串数组类型方法返回类型错误 公共字符串[][]GetAllItems() { FoodCityData.ShoppingBuddyEntities fdContext=新的FoodCityData.ShoppingBuddyEntities(); 可查询查询= 来自fdContext.Item中的c 选择c; List AllfNames=Query.ToList(); int arrayZise=AllfNames.Count; 字符串[,]xx=新字符串[arrayZise,2]; int i=0; int j=0; foreach(所有名称中的项目x) { xx[i,0]=x.ItemName.ToString(); xx[i,1]=x.ItemPrice.ToString(); i++; } return xx[2,2];//如何编写返回类型? }

C# 字符串数组类型方法返回类型错误 公共字符串[][]GetAllItems() { FoodCityData.ShoppingBuddyEntities fdContext=新的FoodCityData.ShoppingBuddyEntities(); 可查询查询= 来自fdContext.Item中的c 选择c; List AllfNames=Query.ToList(); int arrayZise=AllfNames.Count; 字符串[,]xx=新字符串[arrayZise,2]; int i=0; int j=0; foreach(所有名称中的项目x) { xx[i,0]=x.ItemName.ToString(); xx[i,1]=x.ItemPrice.ToString(); i++; } return xx[2,2];//如何编写返回类型? },c#,arrays,string,C#,Arrays,String,此代码段返回类型中有一个错误。我能知道如何正确地写这个方法吗?你有返回类型,你需要返回二维,你可以像这样返回二维数组 public String[][] GetAllItems() { FoodCityData.ShoppingBuddyEntities fdContext = new FoodCityData.ShoppingBuddyEntities(); IQueryable<Item> Query = from c i

此代码段返回类型中有一个错误。我能知道如何正确地写这个方法吗?

你有返回类型,你需要返回二维,你可以像这样返回二维数组

public String[][] GetAllItems() 
    {
        FoodCityData.ShoppingBuddyEntities fdContext = new FoodCityData.ShoppingBuddyEntities();

        IQueryable<Item> Query =
       from c in fdContext.Item
       select c;

        List<Item> AllfNames = Query.ToList();
        int arrayZise = AllfNames.Count;
        String[,] xx = new String[arrayZise,2];
        int i = 0;
        int j = 0;
        foreach(Item x in AllfNames)
        {

                xx[i,0] = x.ItemName.ToString();
                xx[i, 1] = x.ItemPrice.ToString();
                i++;

        }

        return xx[2,2];  // how do i write return type?
    }

假设您的方法在尝试返回时返回where

将方法签名修改为:

public String[,] GetAllItems() 
{
    //your code 
    String[,] xx = new String[arrayZise,2];
    //your code 
    return xx;    
}

当前,您的方法返回单个字符串,这就是错误的原因

您返回的是
字符串
,但返回类型是
字符串[]【】
。我想您要做的是返回一个
字符串[,]

public String[,] GetAllItems() 

您的方法返回类型是,并且由于您的
xx[2,2]
字符串
,因此您的方法返回简单的
字符串
,这就是您得到错误的原因

就这样回来吧


哪个错误?如果你不提供错误,你到底希望我们如何帮助你?“/”应用程序中的服务器错误。无法序列化System.String[,]类型的对象。不支持多维数组。描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。异常详细信息:System.NotSupportedException:无法序列化System.String[,]类型的对象。不支持多维数组。我在运行一个web服务,它说它不允许这样做?你能帮我怎么做吗?
public string[,] GetAllItems() 
{
    ...
    return xx;
}
public String[,] GetAllItems() 
{
  .....
  return xx[2,2];    
}