IanSmellios

Member
I use Visual Studio 2015 and it is always telling me "Name can be simplified." on all the "this."

So, can it be simplified with out breaking the other systems? I have simplified a few and nothing seems to go wrong, but I just see it a lot. I don't want to get to the point of no return.

Thank You for your time :D
 
this. reflects the current instance.
Ex, in a Dog.cs scripot in the constructor, idf you place:
Hue = 100;
it is the same as doing:
this.Hue = 100;

Furthermore, this is useful if you need to send the current instance reference elsewhere, ex: most gumps will take a "Mobile from" parameter, it is where the "this" comes in action.
SendGump( new TestGump( this ) );

Reference:
https://msdn.microsoft.com/en-us/library/dk1507sz.aspx
 
Code:
this.Property = value;

Is mostly always redundant since it can just be

Code:
Property = value;

The only time using "this" to access a property in the instance would be necessary is if there was a local variable defined with the same name, which should never happen with proper casing rules.

Code:
public int Number;

public void Main()
{
    Number = 10;
    PrintNumbers( 5 );
}

public void PrintNumbers( int Number )
{
   Console.WriteLine( Number ); // prints 5
   Console.WriteLine( this.Number ); // prints 10
}
 
Last edited:

Active Shards

  • UO Eventine
    Time Of Legends
    • Players
    • 85 Online
    • 137 Peak
  • The Crossroads
    Mondain's Legacy
    • Players
    • 64 Online
    • 138 Peak
  • Insane UO
    Endless Journey
    • Players
    • 62 Online
    • 101 Peak
  • UO: Felucca
    Renaissance
    • Players
    • 57 Online
    • 87 Peak
  • CALYPSO
    Custom (Modern)
    • Players
    • 28 Online
    • 30 Peak
  • Unchained
    Custom (Classic)
    • Players
    • 26 Online
    • 257 Peak
  • Arth
    Custom (Modern)
    • Players
    • 24 Online
    • 34 Peak
  • UO Phoenix
    Custom (Classic)
    • Players
    • 21 Online
    • 35 Peak
  • UOItalia Reborn
    Custom
    • Players
    • 20 Online
    • 37 Peak
  • UO Enigma
    Custom (Modern)
    • Players
    • 19 Online
    • 172 Peak

Donations

Total amount
$0.00
Goal
$500.00
Back