gpt4 book ai didi

c# - C#中如何清空数组?

转载 作者:太空狗 更新时间:2023-10-29 17:31:39 24 4
gpt4 key购买 nike

我正在使用函数 Array.Clear() 来清空数组,但它会生成错误。这是我使用的代码:

private int[] activeFielderNumber = new int[10];
private string[] activeFielderAction = new string[10];
....
...
....
Array.Clear(activeFielderNumber, 0, activeFielderNumber.Length);
Array.Clear(activeFielderAction, "", activeFielderAction.Length);

错误是:

error CS0103: The name `Array' does not exist in the current context

我该如何解决这个问题?

最佳答案

你用过吗

using System;

还有一点要更正:

Array.Clear(activeFielderAction, "", activeFielderAction.Length);

应该是

Array.Clear(activeFielderAction, 0, activeFielderAction.Length);

最后两个参数是要清除的索引范围。

关于c# - C#中如何清空数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13757390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com