C#中 ,R3 = BLOB.Count(x => x != 0);R4 = BLOB1.Count(x => x != 0);需要用到的指令集
时间: 2023-08-15 14:08:01 浏览: 64
这两行代码用到了 C# 中的 Lambda 表达式和 LINQ 扩展方法。
Lambda 表达式是一种匿名函数,可以用来简化代码和提高可读性。在这里,`x => x != 0` 表示一个输入为 x 的函数,它的返回值是一个布尔值,当 x 不等于 0 时返回 true,否则返回 false。
LINQ 是一种语言集成查询的技术,可以用来对各种数据源进行筛选、排序、分组等操作。在这里,我们使用了 LINQ 扩展方法 `Count`,它用来计算序列中满足指定条件的元素个数。具体来说,`BLOB.Count(x => x != 0)` 表示计算 BLOB 数组中满足 x 不等于 0 的元素个数。
需要注意的是,使用 LINQ 扩展方法需要添加命名空间 `System.Linq`。因此,你需要在代码的开头添加如下语句:
```
using System.Linq;
```
相关问题
R3 = BLOB.Count(x>=x ,x != 0); R4 = BLOB1.Count(x>=x ,x != 0);哪里有错
这两行代码的语法有一些错误,应该改成下面这样:
```
R3 = BLOB.Count(x => x != 0);
R4 = BLOB1.Count(x => x != 0);
```
具体来说,应该使用箭头符号 `=>` 来表示 Lambda 表达式,而不是逗号。另外,`x>=x` 这个条件永远是成立的,因此没有意义,可以直接省略。正确的条件应该是 `x != 0`,表示 x 不等于 0。
最终的代码应该是这样的:
```
R3 = BLOB.Count(x => x != 0);
R4 = BLOB1.Count(x => x != 0);
```
GetIntValue("in1",ref size); float[] BLOB = new float[size]; int[] BLOB1 = new int[size]; GetIntValue("in1",ref S); SetIntValue("out0",S); GetFloatArrayValue("in0",ref BLOB,out S); GetIntArrayValue("in4",ref BLOB1,out S); SetFloatArrayValue("out1",BLOB,0,S); GetFloatValue("in2",ref MIN); GetFloatValue("in3",ref MAX); R1 = 0; R2 = 0; R3 = 0; R4 = 0; R5 = 0; //R3 = BLOB.Count(x => x != 0); //R4 = BLOB1.Count(x => x != 0); for(int i = 0 ; i < S ;i++) { if(BLOB[i]> MAX) { R1++; } if(BLOB[i]< MIN) { R2++; } if(BLOB[i] != 0) { R3++; } if(BLOB1[i] != 0) { R4++; } } //长轴太长太短短数据统计 if((R1>=1||R2>=1 ) && (R4>=size/2)) { res=2; } else { res=1; } SetIntValue("out1",res); SetIntValue("out2",R3); SetIntValue("out3",R4); return true; } } 为什么res还是1
根据代码中的逻辑,如果存在长轴太长或太短的数据并且非零元素个数超过数组大小一半,则将res设为2,否则将res设为1。因此,如果在数组BLOB和BLOB1中存在长轴太长或太短的数据,但非零元素个数不足数组大小一半,那么res将保持为1。也就是说,res的值只与数组中非零元素个数是否超过数组大小一半有关,与长轴太长或太短的数据的具体情况无关。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)