C# for Grasshopper 使用时碰到的一些坑(长期更新)

前言:

本文是一个长期会更新的笔记类文章,主要用于记录在C#4GH时碰到的一些坑

本文继承自以下父类

C#编程碰到的一些坑(长期更新)_言無KAHB的博客-CSDN博客

目录

前言:

1.关于for循环嵌套

2.Grasshopper中C#电池块的out端如何输出内容


1.关于for循环嵌套

1.1 非重复的两两对应

List<Line> neo = new List<Line>();
    for(int i = 0;i < x.Count - 1;i++){
      for(int j = i + 1;j < x.Count;j++){
        neo.Add(new Line(x[i], x[j]));
      }
    }
A = neo;

1.2 重复的两两对应

List<Line> neo = new List<Line>();
    for(int i = 0;i < x.Count;i++){
      for(int j = 0;j < x.Count;j++){
        neo.Add(new Line(x[i], x[j]));
      }
    }
A = neo;

1.3 重复的两两对应中去掉自己与自己对应(加一个判断)

List<Line> neo = new List<Line>();
    for(int i = 0;i < x.Count;i++){
      for(int j = 0;j < x.Count;j++){
        if(j != i){
          neo.Add(new Line(x[i], x[j]));
        }        
      }
    }
A = neo;

注意:C#中不能写这种语句

原因如下: (图片来源:刘铁猛C#教程)

 !=在计算时先参与运算,当 j != i 为false时,语句就停止了不再继续递增

2.Grasshopper中C#电池块的out端如何输出内容

使用Print()方法

猜你喜欢

转载自blog.csdn.net/qq_41904236/article/details/124914058