社区
C#
帖子详情
怎样增加sting数组的长度?谁能解答给谁加分!
cooldht
2002-11-01 03:04:22
string[] childID=new string[5];
…………
给数组赋值
…………
int length=childID.Length;
现在我要增加sting数组的长度,将childID[length]赋值,
而原来数组的内容不能丢失!
怎么办?
...全文
117
4
打赏
收藏
怎样增加sting数组的长度?谁能解答给谁加分!
string[] childID=new string[5]; ………… 给数组赋值 ………… int length=childID.Length; 现在我要增加sting数组的长度,将childID[length]赋值, 而原来数组的内容不能丢失! 怎么办?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
dy_2000_abc
2002-11-01
打赏
举报
回复
使用StringCollection类
snewxf
2002-11-01
打赏
举报
回复
同意楼上!
project
2002-11-01
打赏
举报
回复
如果是用string[]恐怕只能再声明一个更长的string[],然后将数据一一复制到新的数组中,让后释放旧数组。
如果是用ArrayList等Collection类,就简单了。不用管length,直接add就可以了!
yarshray
2002-11-01
打赏
举报
回复
arraylist
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( "\tCount: {0}", myAL.Count );
Console.WriteLine( "\tCapacity: {0}", myAL.Capacity );
Console.Write( "\tValues:" );
PrintValues( myAL );
}
public static void PrintValues( IEnumerable myList ) {
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.
myAL
Count: 3
Capacity: 16
Values: Hello World !
*/
C#中List〈string〉和string[]
数组
之间的相互转换
List和string[]
数组
之间的相互转换,需要的朋友可以参考下
蓝桥杯入门基础的算法代码.zip
蓝桥杯入门基础的算法代码 :包含: 0.递归与递推 1.排序和查找 2.
数组
与矩阵 3.字符串_S
ting
4.dfs_深度优先 5.math(数论) 6.贪心_Greedy 7.动态规划_DynamicPlanning 8.图论
list<>里可以放
数组
吗?
昨天看到一个算法题目,他的示例给的是 3 1 10 1 3 5 7 9 11 13 15 17 19 0 5 1 5 7 11 18 1 0 。。。 这样,第一个数字表示有3组数据。每两行一组,上面一行的第二个数字表示下面一行的数字个数。 但是这个题目没有像乐扣那样,给出方法名和方法参数。我就不知道该怎么写了。 第一行的传参肯定是int a 。然后后面跟一个二维数...
S
ting
数组
转为 Int
数组
假设我们有一个字符串
数组
: String[] strings = {"1", "2", "3"}; 使用Lambda表达式(自Java 8起): int[] array = Arrays.asList(strings).stream().mapToInt(Integer::parseInt).toArray(); ▼另一种方式: int[] array = Arrays.stream(strings).mapToInt(Integer::parseInt).toArray(); ...
(转)Java和JavaScript中String、
数组
长度
的求法
在JS中,字符串类型String和
数组
类型Array都有一个叫length的
长度
属性值,可以用[对象名.length]的方式读取出来,这里的length是对象固有的属性,不是方法,因此不用.length(),而是直接用.length。 在Java中,
数组
是引用数据类型,不是类,因此也是读取固有的length属性得到
数组
长度
,它没有length()方法。但是,java中的String类型是jdk中已经
C#
111,116
社区成员
642,552
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章