77问答网
所有问题
C#高手来看看 怎么给这个 List<int> 赋值呢?
如题所述
举报该问题
推荐答案 2011-07-17
List<int> list=new List<int>();
list.Add(123);
list.Add(234);
list.Add(783);
int[] array=list.ToArray(); //将集合转换成数组;
这就是给 这个反省集合 赋值;
以上集合代码用数组表示如下:
int[] array=new int[3]();
array[0]=123;
array[1]=234;
array[2]=783;
但是 数组和 集合的区别就在于 数组的长度固定,而集合的数据数目 可以不限;
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/Yq8IWWpIN.html
其他回答
第1个回答 2011-07-17
List<int> aa=new List<int>();//初始化
aa.Add(5);//增加第一个元素:5
aa.Add(3);//增加第二个元素:3
List<int>是使用Add()方法来增加元素的
本回答被网友采纳
第2个回答 2011-07-17
是一个数组么?
int List[n]; //n 为数组的个数
for (int i=0;i<n;i++) List[i]=i; // List[i]= 你想要赋的值
如果只是一个integer。
int List;
List=123;
追问
不是数组 nsp.net 里面有这么一个东西,List 尖括号里面可以是很多数据类型,但是我不知道怎么给它赋值。
本回答被提问者采纳
第3个回答 2011-07-19
int year=DateTime.Now.Year;
for(int i=year;i>year-111;year--) //当前年份后推111个年头
{
myComboBox.Items.Add(year);
}
不需要添加arraylist变量
相似回答
C#
List
<
int
>问题
答:
首先说,
List
理论上来说不会丢失数据,您检查一下代码的上下文,是否有跳过某些数据的代码。然后在 new 的时候
赋值
,不知道是什么意思,是 new List 的时候赋值,还是在 new
int
赋值。先说 int 的,因为 int 是值类型,所以不需要 new,所以只要按下面写法写就可以了:List<int>
list
= new Li...
c#如何
定义 类成员
list&
amp;
lt;&
amp;
gt;
答:
public class aa{ public
int
x; public
List
<bb> y = new List<bb> () ;} 或者在使用时再
赋值
也行,如 a.y = new
list
<bb> ();a.y.add(b);PS:我建议你使用后者
在
C#
中
如何
做到将变量赋
给List
集合后,当变量的值改变的时候集合里的对应...
答:
int
id = 1
;List
<MyEntity> list = new List<MyEntity>(); //一个
listlist
[0].ID = id;//把int的值赋
给list
第一个元素的ID属性id+=1;//output list[0].ID;
?
是否等于2
C#
中 int string 这些基类型是值类型,也就是说,第三行代码运行的时候,把id的值 赋给了list[0].ID, ...
C#
相关
List
<
int
> = new List<int>()
答:
List
不是接口,是泛型,IList才是泛型接口,你这样写无法通过编译,关于
list
的具体用法自己百度一下 list 泛型 C
C#
中
list
<>取元素
赋值
问题
答:
double[, ,] controls = new double[coord.Length, 4, 3]; //4:因为每个
LIST
里有4个点; 3:每个点有三个值x, y z for (
int
i = 0; i < coord.Length; i++){ for (int j = 0; j < coord[i].Count / 3; j++){ for (int k = 0; k < 3; k++){ controls[i,j,...
C#
list
值传递
答:
错的是你的代码。数组在
C#
中是引用传递(也就相当于你说的地址传递)。你可以这么写的
List
<List<
int
>> nClass = new List<List<int>>();nClass.Add(new List<int> { 1, 2, 3 });nClass.Add(new List<int> { 1, 2 });nClass.Add(new List<int> { 1 });...
C#
为字符串数组动态
赋值
的问题
答:
方法一是没有new(没有分配空间)方法二是在new的时候没有指定大小,默认是0个元素,所以对其任意一个元素
赋值
都是越界.在
C#
中,数组一般用来存放大小确定的数据.如果数组大小未知,建议使用
List
<>.List<string> a=new List<string>();a.Add("we");MessageBox.Show(a[0]);同时,你可以用a.ToArray()...
大家正在搜
给我看看呗
给你看看呗
你不给我看看
高手
八品高手
最强高手
巅峰高手
顶级高手
全能高手
相关问题
List<int> C# 我想得到里面的值
C# List<int>问题
c#中 list 的=号赋值问题。
C# 高手来教教 我怎么用textbox.text 的值传到...
我在c#中这么写的 list<int> array = ne...
C#/Linq高手来看看这个Cast<int>为什么会失败?
c#声明一个list<int>,其中的元素按从小到大排序,在...
C# 如何将一个int型的变量里的值加到arraylist里