Z
Z
Zefirot2021-11-16 15:25:16
C++ / C#
Zefirot, 2021-11-16 15:25:16

How to process only occupied array elements?

I have an array with objects of this type

public class ClassTest {
    private GameObject o; public GameObject Obj{ get{ return o; } set{ o = value; }}
   ......
    }
private ClassTest ArrayTest = new ClassTest [100];
.....
for(byte i = 0; i < ArrayTest .Length; ++i){ 
  if(i == 4 || i == 56) ArrayTest [i] = new ClassTest { Obj = SomeObj .... };
    else ArrayTest [i] = null;
  }
.....
for(byte i = 0; i < ArrayTest .Length; ++i){
  if(ArrayTest [i] != null){ ....

as you can see, in order to process the necessary objects for me, that is, those that are not null, I need to run the entire array, can this be done somehow simpler?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-11-16
@Zefirot

You can't remove it, you can only hide it out of sight (use Linq).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question