Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: delay and back again record Pin
Eddy Vluggen12-Sep-13 10:42
professionalEddy Vluggen12-Sep-13 10:42 
GeneralRe: delay and back again record Pin
Eddy Vluggen13-Sep-13 7:06
professionalEddy Vluggen13-Sep-13 7:06 
Questiontv show control in c# Pin
eng.iris11-Sep-13 17:54
eng.iris11-Sep-13 17:54 
AnswerRe: tv show control in c# Pin
Abhinav S11-Sep-13 18:24
Abhinav S11-Sep-13 18:24 
General"this" keyword Pin
N8tiv11-Sep-13 17:17
N8tiv11-Sep-13 17:17 
GeneralRe: "this" keyword Pin
Ron Beyer11-Sep-13 17:35
professionalRon Beyer11-Sep-13 17:35 
GeneralRe: "this" keyword Pin
N8tiv11-Sep-13 18:08
N8tiv11-Sep-13 18:08 
GeneralRe: "this" keyword Pin
Ron Beyer11-Sep-13 18:15
professionalRon Beyer11-Sep-13 18:15 
No, I guess its a little difficult to understand...

Every time you use the "new" operator you create an instance of the class. Think of a class as how an object behaves or can be interacted with in memory. Until you create an instance of it (for instance classes), you can't interact with it. Static methods do not get instantiated with the new operator, so they are not instance classes.

Sometimes you need to interact (internally) with the current instance of the class, that's when you use the "this" keyword.

For example, if you have:

C#
public class Point
{
    int x;
    int y;

    public Point(int x, int y)
    {
        this.x = x;    //this.x means the instance public member x, assigned to the method parameter x
        this.y = y;
    }
}


In the above, you need a way to differentiate between the x member of the class, and the x parameter of the method. You can do this with the "this" keyword, which says "set the member x of this instance of the class to x (the parameter of the method).

You still instantiate it with something like:

C#
Point p = new Point(5,10);


this is only used internally in classes, the "this" keyword can only refer to the current instance of the class that you are in.
GeneralRe: "this" keyword Pin
N8tiv11-Sep-13 18:26
N8tiv11-Sep-13 18:26 
GeneralRe: "this" keyword Pin
Ron Beyer11-Sep-13 18:50
professionalRon Beyer11-Sep-13 18:50 
GeneralRe: "this" keyword Pin
Abhinav S11-Sep-13 18:23
Abhinav S11-Sep-13 18:23 
GeneralRe: "this" keyword Pin
V.11-Sep-13 21:49
professionalV.11-Sep-13 21:49 
QuestionDrawing a line that follows a moving point Pin
Davebandit11-Sep-13 4:40
Davebandit11-Sep-13 4:40 
AnswerRe: Drawing a line that follows a moving point Pin
Richard MacCutchan11-Sep-13 6:22
mveRichard MacCutchan11-Sep-13 6:22 
GeneralRe: Drawing a line that follows a moving point Pin
Davebandit11-Sep-13 8:28
Davebandit11-Sep-13 8:28 
GeneralRe: Drawing a line that follows a moving point Pin
Eddy Vluggen11-Sep-13 11:09
professionalEddy Vluggen11-Sep-13 11:09 
GeneralRe: Drawing a line that follows a moving point Pin
Davebandit12-Sep-13 1:04
Davebandit12-Sep-13 1:04 
GeneralRe: Drawing a line that follows a moving point Pin
Richard MacCutchan11-Sep-13 20:53
mveRichard MacCutchan11-Sep-13 20:53 
Questionnested classes Pin
Member 1026649411-Sep-13 1:51
Member 1026649411-Sep-13 1:51 
AnswerRe: nested classes Pin
Member 1026649411-Sep-13 2:00
Member 1026649411-Sep-13 2:00 
GeneralRe: nested classes Pin
Keith Barrow11-Sep-13 2:17
professionalKeith Barrow11-Sep-13 2:17 
GeneralRe: nested classes Pin
Member 1026649411-Sep-13 3:13
Member 1026649411-Sep-13 3:13 
GeneralRe: nested classes Pin
Dave Kreskowiak11-Sep-13 4:54
mveDave Kreskowiak11-Sep-13 4:54 
GeneralRe: nested classes Pin
NotPolitcallyCorrect11-Sep-13 2:41
NotPolitcallyCorrect11-Sep-13 2:41 
AnswerRe: nested classes Pin
V.11-Sep-13 3:20
professionalV.11-Sep-13 3:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.