Classify object type and store in array

Hello community, i’ve seen alot of questions but none of them seems to suit my needs. The thing is simple, i will receive an object with a script component of certain type ( say weapon boot or armor ), and i need to store each one in its corresponding array. For example i receive an object with the Armor script attached to it, and i have to store that in the Armor array. The thing is that i cant find a “proper” solution to this, i try’ed using the getComponent but i cant ask if “its not null then add to array”, what i could do is ask if its null, and do nothing, else add to array…but doesn’t seem to be the best approach.

Any suggestions ? Thanks in advance.

PS: about the get component thing:
if(value.getComponent() =! null) //i can’t use the =! on null things
so

if(value.getComponent<Armor>() == null){
 //nothing ._.
}
else
   Armor.Add(value);   //there should   be a better way... 

tho i didn’t try this so even this may not work.

Putting the response here since comments can’t show code correctly. What you’re doing is ok, there may be a slightly better way in the future but don’t worry about it too hard. Often you’ve got to work with the first choice before the better choice will become obvious for your needs. Here’s a slight re-write that only requires one getComponent call (which can be a little slow)

Armor armor = value.getComponent<Armor>();
if(armor != null) //!= not =!
{
   Armor.Add(armor);
}