INT转换为int [] [英] Convert int to int[]

查看:167
本文介绍了INT转换为int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据,我试图让datset的所有ID成数据行,终于将其保存在一个int数组。它不是为我工作。它说不能隐从int类型转换为int []

I have a dataset and i am trying to get all the Ids of the datset into a datarow to finally save it in a int array. Its not working for me. It says "Cannot implicitly convert from type int to int[]"

Dataset ds = new BusinessLogic().Getsamples(MerchantID);

Datarow dr = ds.Tables[0].Rows[0];

int[] SampleID = Convert.ToInt32(dr["Id"]);

在此先感谢..

Thanks in advance..

推荐答案

您必须创建一个新的int数组,并把INT在那里。

You have to create a new int array and put the int in there.

int sampleID = new int[1];
sampleID[0] = Convert.ToInt32(dr["Id"]);

我认为这会速记工作太:

I think this shorthand will work too:

int[] SampleID = new int[]{Convert.ToInt32(dr["Id"])};

这篇关于INT转换为int []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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