字符串数组类型的方法返回类型错误 [英] String Array type method return type error

查看:141
本文介绍了字符串数组类型的方法返回类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?
    }

林刚开这个code段返回类型错误。我能知道如何这个方法正确的方法写的?

Im gettin an error in this code segment return type. Can i know how to write this method correct way?

推荐答案

您有铁血阵列返回类型,你需要返回二维的 Rrectangular阵列,您可以返回这样的二维数组。

You have Jagged Array return type and you need to return two dimensional Rrectangular Array, You can return two dimensional array like this.

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

这篇关于字符串数组类型的方法返回类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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