Is there a good (technical) argument to use either one and not the other of the following ways to check if an instance is of a specific type? Is one of them error prone and should be avoided?
// Use "is".
bool isFolder = this.Parent is FolderEntity;
// Use "as".
bool isFolder = (this.Parent as FolderEntity) != null;
The intention of the code is to find out of the instance is a FolderEntity
. In that case, the code will branch. The code is not interested in the resulting object.
From a point of clear code, I would use "is". What I was wondering however if there is a reason to prefer the "as" way of doing it.