欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > C# >内容正文

C#

C#通过Array.Clear部分清除数组的代码

发布时间:2025/7/14 C# 68 豆豆
生活随笔 收集整理的这篇文章主要介绍了 C#通过Array.Clear部分清除数组的代码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

将代码过程中重要的一些代码片段记录起来,如下的代码是关于C#通过Array.Clear部分清除数组的代码,希望对大家有所用。

using System;

class ArrayClear
{

public static void Main()
{
int[] integers = { 1, 2, 3, 4, 5 };
DumpArray ("Before: ", integers);
Array.Clear (integers, 1, 3);
DumpArray ("After: ", integers);
}

public static void DumpArray (string title, int[] a)
{
Console.Write (title);
for (int i = 0; i < a.Length; i++ )
{
Console.Write("[{0}]: {1, -5}", i, a[i]);
}
Console.WriteLine();
}
}

这段代码的输出结果如下:

Before: [0]: 1 [1]: 2 [2]: 3 [3]: 4 [4]: 5
After: [0]: 1 [1]: 0 [2]: 0 [3]: 0 [4]: 5

转载于:https://blog.51cto.com/14135053/2385212

总结

以上是生活随笔为你收集整理的C#通过Array.Clear部分清除数组的代码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。