this


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: this

  1. #1
    Humberto Morales Guest

    this

    When I want to use a method in my own class is it faster to call it via
    this.MethodName() or just the MethodName(). Does it really matter?



  2. #2
    Nathan Alden Guest

    Re: this

    Doesn't matter. The compiler compiles it to the same IL code anyway.
    --
    Nathan Alden
    Microsoft Certified Solution Developer



  3. #3
    Humberto Morales Guest

    Re: this

    Thanks. Although I will probably stick to this because of readability.


    "Nathan Alden" <liverpg@hotmail.com> wrote in message
    news:3c828a40@10.1.10.29...
    > Doesn't matter. The compiler compiles it to the same IL code anyway.
    > --
    > Nathan Alden
    > Microsoft Certified Solution Developer
    >
    >




  4. #4
    Nathan Alden Guest

    Re: this

    Actually, I would not recommend that. I would be quite annoyed if all I saw
    on a code page were "this." everywhere. I can figure out where the
    method/property/field exists simply by inspecting it. "this." is a little
    too verbose.
    --
    Nathan Alden
    Microsoft Certified Solution Developer



  5. #5
    Humberto Morales Guest

    Re: this

    Great, what are your thoughts on const should the appear in all uppercase or
    camel notation?

    "Nathan Alden" <liverpg@hotmail.com> wrote in message
    news:3c828c3c@10.1.10.29...
    > Actually, I would not recommend that. I would be quite annoyed if all I

    saw
    > on a code page were "this." everywhere. I can figure out where the
    > method/property/field exists simply by inspecting it. "this." is a little
    > too verbose.
    > --
    > Nathan Alden
    > Microsoft Certified Solution Developer
    >
    >




  6. #6
    Jonathan Allen Guest

    Re: this

    The docs say that constants should use PascalCase. Of course, that only
    applies to ones marked public.

    --
    Jonathan Allen


    "Humberto Morales" <humberto@socal.rr.com> wrote in message
    news:3c828ee9$1@10.1.10.29...
    > Great, what are your thoughts on const should the appear in all uppercase

    or
    > camel notation?
    >
    > "Nathan Alden" <liverpg@hotmail.com> wrote in message
    > news:3c828c3c@10.1.10.29...
    > > Actually, I would not recommend that. I would be quite annoyed if all I

    > saw
    > > on a code page were "this." everywhere. I can figure out where the
    > > method/property/field exists simply by inspecting it. "this." is a

    little
    > > too verbose.
    > > --
    > > Nathan Alden
    > > Microsoft Certified Solution Developer
    > >
    > >

    >
    >




  7. #7
    jaleel Guest

    Re: this


    I would only recomend the "this" if your parameter names in a constructor
    or a set method is the same to that of the member variable names. Secondly,
    when you are dealing with windows forms and you have created a class to deal
    with logic from an event on the main from and that class needs to be instantiated
    in the main form. By passing the this to that class, you will have access
    to the main form's controls.

    -Jaleel


    "Jonathan Allen" <greywolfghost@cox.net> wrote:
    >The docs say that constants should use PascalCase. Of course, that only
    >applies to ones marked public.
    >
    >--
    >Jonathan Allen
    >
    >
    >"Humberto Morales" <humberto@socal.rr.com> wrote in message
    >news:3c828ee9$1@10.1.10.29...
    >> Great, what are your thoughts on const should the appear in all uppercase

    >or
    >> camel notation?
    >>
    >> "Nathan Alden" <liverpg@hotmail.com> wrote in message
    >> news:3c828c3c@10.1.10.29...
    >> > Actually, I would not recommend that. I would be quite annoyed if all

    I
    >> saw
    >> > on a code page were "this." everywhere. I can figure out where the
    >> > method/property/field exists simply by inspecting it. "this." is a

    >little
    >> > too verbose.
    >> > --
    >> > Nathan Alden
    >> > Microsoft Certified Solution Developer
    >> >
    >> >

    >>
    >>

    >
    >



  8. #8
    Jason Guest

    Re: this


    I was using "this" for readability, but it's difficult to type, it clutters
    up my code, and I sometimes forget to put it in. That does not seem to increase
    readability to me.

    What I found works, and works well, is if you develop the convention of prefixing
    class variables with an underscore.

    private string _myVariable = "";

    That way, you get the benefit of readability without the clutter, and the
    compiler usually tells you when you have made a mistake.

    This also removes all ambiguity when you have a property and a class variable
    with the same name.

    Try it out and see if you like it. I thought it was silly the first time
    I saw it, but now that I have started using it, I think it's a really amazing
    coding convention!

  9. #9
    Jonathan Allen Guest

    Re: this

    > I would only recomend the "this" if your parameter names in a constructor
    > or a set method is the same to that of the member variable names.


    You shouldn't use a naming scheme that relies on "this" to resolve
    ambiguities, as it leads to logic errors.

    --
    Jonathan Allen


    "jaleel" <jaleel_severin@yahoo.com> wrote in message
    news:3c83dd19$1@10.1.10.29...
    >
    > I would only recomend the "this" if your parameter names in a constructor
    > or a set method is the same to that of the member variable names.

    Secondly,
    > when you are dealing with windows forms and you have created a class to

    deal
    > with logic from an event on the main from and that class needs to be

    instantiated
    > in the main form. By passing the this to that class, you will have access
    > to the main form's controls.
    >
    > -Jaleel
    >
    >
    > "Jonathan Allen" <greywolfghost@cox.net> wrote:
    > >The docs say that constants should use PascalCase. Of course, that only
    > >applies to ones marked public.
    > >
    > >--
    > >Jonathan Allen
    > >
    > >
    > >"Humberto Morales" <humberto@socal.rr.com> wrote in message
    > >news:3c828ee9$1@10.1.10.29...
    > >> Great, what are your thoughts on const should the appear in all

    uppercase
    > >or
    > >> camel notation?
    > >>
    > >> "Nathan Alden" <liverpg@hotmail.com> wrote in message
    > >> news:3c828c3c@10.1.10.29...
    > >> > Actually, I would not recommend that. I would be quite annoyed if all

    > I
    > >> saw
    > >> > on a code page were "this." everywhere. I can figure out where the
    > >> > method/property/field exists simply by inspecting it. "this." is a

    > >little
    > >> > too verbose.
    > >> > --
    > >> > Nathan Alden
    > >> > Microsoft Certified Solution Developer
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center