创建一个必须包含五个十进制元素值的arraylist [英] Create an arraylist which must containing five decimal element values

查看:52
本文介绍了创建一个必须包含五个十进制元素值的arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数组列表的十进制值出现问题,因为我无法将其变为值。这是第一次这样做。



我尝试过:



Just having a problem on my decimal values for my array list, as I can't make it into a values. As it the first time doing it.

What I have tried:

ArrayList list = new ArrayList();
            decimal[] values = { "5, 7, 9, 11, 13" };
            list.Add(5);
            list.Add(7);
            list.Add(9);
            list.Add(11);
            list.Add(13);
            //
            // Use ArrayList with method.
            //
            Example(list);
        }

        static void Example(ArrayList list)
        {
            foreach (int i in list)
            {
                Console.WriteLine(i);
            }
        }

推荐答案

这些不是十进制值,它们是整数。

对于实际小数,请尝试:

Those aren't decimal values, they are integers.
For actual decimals, try:
list.Add(5m);
list.Add(7m);
list.Add(9m);
list.Add(11m);
list.Add(13m);

对于浮点数,请尝试:

For floating point, try:

list.Add(5f);
list.Add(7f);
list.Add(9f);
list.Add(11f);
list.Add(13f);



对于双打,请使用:


For doubles, use:

list.Add(5d);
list.Add(7d);
list.Add(9d);
list.Add(11d);
list.Add(13d);





最重要的是,不要使用ArrayList - 它们被取代超过11几年前由通用替代清单< T>这是强类型和woudln; t有这个问题....



Best of all, don't use an ArrayList - they were superseded over eleven years ago by the Generic alternative List<T> which is strongly typed and woudln;t have this problem....


这篇关于创建一个必须包含五个十进制元素值的arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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