-
[Solved] GetType
Can't I do this?
Code:
public void AddAttribute(Attribute a)
{
if (a == null)
throw new NullReferenceException();
if (a is this.CreateAttribute().GetType())
throw new InvalidAttributeException();
attributes.Add(a);
}
It says, Invalid expression term ')', etc... Thanks in advance!
-
Re: GetType
The "is" keyword is used with types, not instances of the Type class. The GetType method returns an instance of the Type class. You use "is" something like this:How you're using it is equivalent to this:
Code:
if (str is typeof(string))
which is not valid. What you need to do is get two Type references and compare them:
Code:
if (a.GetType() == this.CreateAttribute().GetType())
-
Re: GetType