获取in datareader int值时哪个更好? [英] Which is better to use when getting the in datareader int value?

查看:82
本文介绍了获取in datareader int值时哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

The code would be like:

string Acc_ID;

//[0] is the ID whereas the [2] is the Account type(Admin, User, etc.)
Acct_ID = rdr.GetInt32[0] + " " + rdr.GetString[2];
lblID.Text = Acc_ID;



我应该这样做,还是使用Cast来让它更快地执行?谢谢谁能提供帮助!对不起,如果这听起来很烦人我只是新来的C#。



我尝试过:



这是我试过的:rdr.GetInt32 [0],rdr.GetInt32 [0] .ToString(),Convert.ToString(rdr.GetInt32 [0])和(int)rdr.GetInt32 [0]。


Should I make it just like that or use Cast on them to make it execute faster? Thank you whoever can help! Sorry if it sounds annoying I'm just new to C#.

What I have tried:

Here is what I tried: rdr.GetInt32[0], rdr.GetInt32[0].ToString(), Convert.ToString(rdr.GetInt32[0]), and (int)rdr.GetInt32[0].

推荐答案

你不需要强制转换,.GetInt32返回一个32位整数,.String返回一个字符串。



如果需要将字符串转换成字符串,那么你需要的唯一一个转换是。



You do not need to cast, .GetInt32 returns an 32 bit integer, .String returns a string.

The only cast you need is the one to convert the int to a string if you need it as a string.

Acct_ID = rdr.GetInt32[0].ToString + " " + rdr.GetString[2];


这篇关于获取in datareader int值时哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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