关于ASP.NET(C#)的变量类型转换 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string strT = Convert.ToString(变量); using System;class Sample { public static void Main() { string nl = Environment.NewLine; string str = "{0}Return the Int64 equivalent of the following base types:{0}"; bool xBool = false; short xShort = 1; int xInt = 2; long xLong = 3; float xSingle = 4.0f; double xDouble = 5.0; decimal xDecimal = 6.0m; string xString = "7"; char xChar = '8'; // '8' = hexadecimal 38 = decimal 56 byte xByte = 9;// The following types are not CLS-compliant. ushort xUshort = 120; uint xUint = 121; ulong xUlong = 122; sbyte xSbyte = 123;// The following type cannot be converted to an Int64.// DateTime xDateTime = DateTime.Now; Console.WriteLine(str, nl); Console.WriteLine("Boolean: {0}", Convert.ToInt64(xBool)); Console.WriteLine("Int16: {0}", Convert.ToInt64(xShort)); Console.WriteLine("Int32: {0}", Convert.ToInt64(xInt)); Console.WriteLine("Int64: {0}", Convert.ToInt64(xLong)); Console.WriteLine("Single: {0}", Convert.ToInt64(xSingle)); Console.WriteLine("Double: {0}", Convert.ToInt64(xDouble)); Console.WriteLine("Decimal: {0}", Convert.ToInt64(xDecimal)); Console.WriteLine("String: {0}", Convert.ToInt64(xString)); Console.WriteLine("Char: {0}", Convert.ToInt64(xChar)); Console.WriteLine("Byte: {0}", Convert.ToInt64(xByte)); Console.WriteLine("DateTime: There is no example of this conversion because"); Console.WriteLine(" a DateTime cannot be converted to an Int64.");// Console.WriteLine("{0}The following types are not CLS-compliant.{0}", nl); Console.WriteLine("UInt16: {0}", Convert.ToInt64(xUshort)); Console.WriteLine("UInt32: {0}", Convert.ToInt64(xUint)); Console.WriteLine("UInt64: {0}", Convert.ToInt64(xUlong)); Console.WriteLine("SByte: {0}", Convert.ToInt64(xSbyte)); }} string strT = (string)变量; 我定义的一个数组a[]想把他转换float型,怎么做呢?? 我定义了一个字符串数组,想把他转换成float型的请问:此转换语句怎么写呢??谢谢!! string [] s={"0.11","0.33","0.44"}; double[] f=new double[3]; for (int i=0;i<s.Length ;i++) { f[i]=Convert.ToDouble(s[i]); } } 变量类型转换一般都会使用Convert函数更深奥的没接触过,一同等待高手! string strT = (string)变量;string strT = (变量).tostring();int strT = (int)变量;int strT=Convert.int32(变量);有什么区别??????? to:boytomato(深爱一人叫颖的女孩!)不可以啊,错误提示为:输入字符串的格式不正确。 请教一个读取HTML字符串元素的方法 大虾门 看看这个 为啥每次刷新都执行 关于连接mysql的问题 为什么我的参数不能保持? db2 带out参数的存储过程,急 请教高手 如何启用模拟登录的验证方式,windows验证和这个有什么区别,一定给分 dropdownlist绑定后使新增加行显示在第一列的问题??up就有分哦 table怎么使用 求助!!!!!!!!!!关于datalist里的控件如何获得值的问题。 怎样判断Request.Querystring["id"]的值为有效整数?(c#) DataGird中如何将一个从数据库取得的字段进行转换显示?
{
public static void Main()
{
string nl = Environment.NewLine;
string str = "{0}Return the Int64 equivalent of the following base types:{0}";
bool xBool = false;
short xShort = 1;
int xInt = 2;
long xLong = 3;
float xSingle = 4.0f;
double xDouble = 5.0;
decimal xDecimal = 6.0m;
string xString = "7";
char xChar = '8'; // '8' = hexadecimal 38 = decimal 56
byte xByte = 9;// The following types are not CLS-compliant.
ushort xUshort = 120;
uint xUint = 121;
ulong xUlong = 122;
sbyte xSbyte = 123;// The following type cannot be converted to an Int64.
// DateTime xDateTime = DateTime.Now; Console.WriteLine(str, nl);
Console.WriteLine("Boolean: {0}", Convert.ToInt64(xBool));
Console.WriteLine("Int16: {0}", Convert.ToInt64(xShort));
Console.WriteLine("Int32: {0}", Convert.ToInt64(xInt));
Console.WriteLine("Int64: {0}", Convert.ToInt64(xLong));
Console.WriteLine("Single: {0}", Convert.ToInt64(xSingle));
Console.WriteLine("Double: {0}", Convert.ToInt64(xDouble));
Console.WriteLine("Decimal: {0}", Convert.ToInt64(xDecimal));
Console.WriteLine("String: {0}", Convert.ToInt64(xString));
Console.WriteLine("Char: {0}", Convert.ToInt64(xChar));
Console.WriteLine("Byte: {0}", Convert.ToInt64(xByte));
Console.WriteLine("DateTime: There is no example of this conversion because");
Console.WriteLine(" a DateTime cannot be converted to an Int64.");
//
Console.WriteLine("{0}The following types are not CLS-compliant.{0}", nl);
Console.WriteLine("UInt16: {0}", Convert.ToInt64(xUshort));
Console.WriteLine("UInt32: {0}", Convert.ToInt64(xUint));
Console.WriteLine("UInt64: {0}", Convert.ToInt64(xUlong));
Console.WriteLine("SByte: {0}", Convert.ToInt64(xSbyte));
}
}
请问:此转换语句怎么写呢??谢谢!!
double[] f=new double[3];
for (int i=0;i<s.Length ;i++)
{
f[i]=Convert.ToDouble(s[i]);
} }
string strT = (变量).tostring();int strT = (int)变量;
int strT=Convert.int32(变量);有什么区别???????
不可以啊,错误提示为:
输入字符串的格式不正确。