Results 1 to 3 of 3

Thread: [Solved] GetType

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    [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!
    Last edited by nebulom; Jun 2nd, 2006 at 12:25 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    Code:
    if (str is string)
    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())
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: GetType

    Millions of thanks JM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width