What is the meaning of "this" in C#

what is the meaning of symbol
meanings of words
meaning
meaning
meaning in text
meaning of meaning
what does mean
meaning of names

Could anyone please explain the meaning "this" in C#?

Such as:

// complex.cs
using System;

public struct Complex 
{
   public int real;
   public int imaginary;

   public Complex(int real, int imaginary) 
   {
      this.real = real;
      this.imaginary = imaginary;
   }

The this keyword is a reference to the current instance of the class.

In your example, this is used to reference the current instance of the class Complex and it removes the ambiguity between int real in the signature of the constructor vs. the public int real; in the class definition.

MSDN has some documentation on this as well which is worth checking out.

Though not directly related to your question, there is another use of this as the first parameter in extension methods. It is used as the first parameter which signifies the instance to use. If one wanted to add a method to the String class you could simple write in any static class

public static string Left(this string input, int length)
{
    // maybe do some error checking if you actually use this
    return input.Substring(0, length); 
}

See also: http://msdn.microsoft.com/en-us/library/bb383977.aspx

Meaning, indicating an association between two entities, typically one of belonging. what definition: 1. used to ask for information about people or things: 2. used in questions that show you are…. Learn more.


The this keyword refers to the current instance of the class and is also used as a modifier of the first parameter of an extension method.

this (C# reference) - MSDN C# Keywords - MSDN

THE, expressing the relationship between a direction and a point of reference. Definition of meaning. 1 a : the thing one intends to convey especially by language : purport Do not mistake my meaning. b : the thing that is conveyed especially by language : import Many words have more than one meaning.


Nate and d_r_w have the answer. I just want to add that in your code specifically the this. does in deed refere to the member of the CLASS to distinguish from the arguments to the FUNCTION. So, the line

this.real = real

means assign the value of the function (in this case, constructor) parameter 'real' to the class member 'real'. In general you'd use case as well to make the distinction clearer:

public struct Complex
{
    public int Real;
    public int Imaginary;
    public Complex(int real, int imaginary)
    {
        this.Real = real;
        this.Imaginary = imaginary;
    }
}

OF, expressing the relationship between a general category or type and the thing being specified which belongs to such a category. n. 1. the sense or significance of a word, sentence, symbol, etc; import; semantic or lexical content. 2. the purpose underlying or intended by speech, action, etc. 3. the inner, symbolic, or true interpretation, value, or message: the meaning of a dream. 4. valid content; efficacy: a law with little or no meaning. 5.


When the body of the method

public Complex(int real, int imaginary) {
    this.real = real;
    this.imaginary = imaginary;
}

is executing, it is executing on a specific instance of the struct Complex. You can refer to the instance that the code is executing on by using the keyword this. Therefore you can think of the body of the method

public Complex(int real, int imaginary) {
    this.real = real;
    this.imaginary = imaginary;
}

as reading

public Complex(int real, int imaginary) {
    assign the parameter real to the field real for this instance
    assign the parameter imaginary to the field imaginary for this instance
}

There is always an implicit this so that the following are equivalent

class Foo {
    int foo;
    public Foo() {
        foo = 17;
    }
}

class Foo {
    int foo;
    public Foo() {
        this.foo = 17;
    }
}

However, locals take precedence over members so that

class Foo {
    int foo;
    public Foo(int foo) {
        foo = 17;
    }
}

assigns 17 so the variable foo that is a parameter to the method. If you want to assign to the instance member when you have a method where there is a local with the same name, you must use this to refer to it.

WHAT'S THE MEANING OF THIS? (phrase) definition and synonyms , following a noun derived from or related to a verb. The answer to the meaning of life is too profound to be known and understood. You will never live if you are looking for the meaning of life. The meaning of life is to forget about the search for the meaning of life.


this references the instance of the class.

Meaning, where the head of the phrase is a predicative adjective. “It depends on what the meaning of the word ‘is’ is. If the—if he—if ‘is’ means is and never has been, that is not—that is one thing. If it means there is none, that was a


Mean, indicating the relationship between a verb and an indirect object. Meaning & Origin Did you know that Matthew 1.6m means Gift of God? Find out if your name means beauty, hope, power, bravery, or something different. Learn the origin of your name: English, Hebrew, Spanish, German, or another origin.


Define, "it would be just a quarter of three in New York" Submitted by Christopher on March 7, 2018 - 3:55am. The meaning of life is to live. It is a simple answer and is so appropriate in that the complex interactions and causal reactions that make up


6 words with meanings that will surprise you, of definition: 1. used to show possession, belonging, or origin: 2. used after words or phrases expressing…. Learn more. 7 Letter-based symbols. 7.1 Letter modifiers. 7.2 Symbols based on Latin letters. 7.3 Symbols based on Hebrew or Greek letters. 11 External links. This list is organized by symbol type and is intended to facilitate finding an unfamiliar symbol by its visual appearance. For a related list organized by mathematical topic, see List of mathematical