c# - 如何使用来自不同脚本的变量作为方法参数
问题描述
我一直在努力使用需要检查的方法,然后更改来自单独脚本和对象的变量。我正在尝试检查数组中是否存在非空条目以及占位符中尚未使用的条目。当这两个都为真时,它应该将该数组的内容复制到我的 actualReadIn 字符串变量中,该变量保存在另一个脚本中。类别是我正在读取的字符串数组。
这是我的代码:
int checkForNotNull(string[] a)
{
for (int x = 0; x < a.Length; x++)
{
if (a[x]!= "" && orbScript1.actualReadIn != a[x] && orbScript2.actualReadIn != a[x] && orbScript3.actualReadIn != a[x] && orbScript4.actualReadIn != a[x]
&& orbScript5.actualReadIn != a[x] && orbScript6.actualReadIn != a[x]&& orbScript7.actualReadIn != a[x] && orbScript8.actualReadIn != a[x])
//^^ This should both check to see if the entry is not nothing, and see if the entry matches any others orbs.
return x;
}
return -1;
}
^^ 此代码检查以确保其他占位符尚未包含数组条目
void readArray(string actualRead)
{
if (taskPhase == 1)
{
if (actualRead == "")
{
actualRead = Categories[checkForNotNull(Categories)];
}
}
if (taskPhase == 2)
{
}
}
^^ 这个脚本的参数应该是 orbScript1.actualReadIn。这是我要填充的字符串变量。当我尝试调用该方法时出现问题
readArray(orbScript1.actualReadIn);
这没有错误,但它没有填充 orbScript1 上的值。我对此很陌生,所以如果我正在做一些不好的形式或不常见的做法,请告诉我。
如果您需要澄清,我会尽我所能提供。
谢谢。
解决方案
我想我明白了。事实证明, readArray() 完全没用。我实际得到输出的方式是
if (orbScript1.actualReadIn == "")
{
orbScript1.actualReadIn = Categories[checkForNotNull (Categories)];
}
此方法不要求脚本之外的参数,并填充对象上的 actualReadIn 变量。
推荐阅读
- python - 为什么 contextlib.redirect_stderr 上下文管理器没有捕获异常输出?
- typescript - 获取传入 props 的组件的 props 类型
- reactjs - FilePond:如果 allowBrowse 为 true,则在触发 onactivatefile 事件时始终显示文件打开对话框
- flutter - 使用 http Flutter 获取 API
- java - Android OpenGL:纹理和颜色问题
- jboss7.x - 摆脱 MANIFEST.MF 文件
- solidity - 如何查询RNS域名的到期日?
- django - Django 无法使用 pk MultiValueDictKeyError 以外的查询参数测试 API 补丁方法
- javascript - 在 Javascript 中设置交通灯的计时器
- r - Plotly:使用 R 更新参数中的多个数据属性