本文介绍了将ArrayList对象转换为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在下面的代码中,我希望ArrayList对象x的类型为double。 我该怎么做? - -Thanks SqlConnection objConnection = new SqlConnection(" server =(local)\\SQLEXPRESS; database = Northwind; integrated security = true;"); String strSQL =" SELECT ProductName,UnitsInStock FROM Products WHERE UnitsInStock> = 50" ;; SqlCommand objCommand = new SqlCommand(strSQL,objConnection); objConnection.Open(); ArrayList strLabel = new ArrayList(); ArrayList x = new ArrayList(); SqlDataReader dr = objCommand.ExecuteReader(); while(dr.Read()) { object [] values1 = new object [0]; dr.GetValues (values1); strLabel.Add(values1); object [] values2 = new object [1]; dr.GetValues(values2); x.Add(values2) ; } dr.Close(); objConnection.Close(); 解决方案 如果您知道数据行中的第一项是字符串, ,第二项是双精度,并且它们都不能为空,那么 你可以这样做: ProductName.Add((string)dr.GetValue(0)); UnitsInStock.Add((double) Dr.GetValue(1)); In the following code, I want ArrayList object x to be of type double.How can I do that?--ThanksSqlConnection objConnection = newSqlConnection("server=(local)\\SQLEXPRESS; database=Northwind; integratedsecurity=true;");String strSQL = "SELECT ProductName, UnitsInStock FROM ProductsWHERE UnitsInStock >= 50";SqlCommand objCommand = new SqlCommand(strSQL, objConnection);objConnection.Open();ArrayList strLabel = new ArrayList();ArrayList x = new ArrayList();SqlDataReader dr = objCommand.ExecuteReader();while (dr.Read()){object[] values1 = new object[0];dr.GetValues(values1);strLabel.Add(values1);object[] values2 = new object[1];dr.GetValues(values2);x.Add(values2);}dr.Close();objConnection.Close(); 解决方案 这篇关于将ArrayList对象转换为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 18:15