-1

How do I use the propfull tab tab gadget in visual studio?

Class Foo
{
public int regirsterR0
    {
        get { return R0; }
        set { R0 = value; }
    }
}

How would I use the get and set methods from another class? Let's say this method is in a class called foo. How would I use the get and set from foo in goo?

Class Goo
{
  Foo g= new Foo();
  g.regirsterR0.Get?????
}
Dragael
  • 9
  • 5

3 Answers3

3

First, thats called a snippet (and there are a bunch of others!). This one creates a full property (MSDN) definition.

To answer your question; you just use it as if it were a field:

var test = g.Register0; //invokes get
g.Register0 = 2; //invokes set

get and set are nice method abstractions that are called when the associated property is accessed or assigned to.

Note that you don't even need the snippet; you could have used an auto-property:

public int RegisterR0 { get; set; } //Properties are PascalCase!
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
2

Get and Set is not a value or method. Actually they are property like a control mechanism. (encapsulation principle)

for ex:

var variable = g.Register0; // so it is get property. // like a var variable = 5;
g.Register0 = 5; // so it is set property.

Look msdn explaining.

Osman Villi
  • 346
  • 2
  • 24
0

You just forgot create method. :-)

class Foo
{
    private int regirsterR0;

    public int RegirsterR0
    {
        get { return regirsterR0; }
        set { regirsterR0 = value; }
    }
}

class Goo
{
    Foo g = new Foo();

    void myMethod()
    {
        // Set Property
        g.RegirsterR0 = 10;
        // Get property
        int _myProperty = g.RegirsterR0;
    }

}

If you want initialize new object of class Foo with Value you can:

class Foo
{
    private int regirsterR0;

    public int RegirsterR0
    {
        get { return regirsterR0; }
        set { regirsterR0 = value; }
    }
}

class Goo
{
    Foo g = new Foo() { RegirsterR0 = 10 };

    void myMethod()
    {
        Console.WriteLine("My Value is: {0}", g.RegirsterR0);
    }
}

But usualy you don't need use propfull. Will be fine if you use prop + 2xTAB. Example:

class Foo
{
    public int RegirsterR0 { get; set; }
}

class Goo
{
    Foo g = new Foo() { RegirsterR0 = 10 };

    void myMethod()
    {
        Console.WriteLine("My Value is: {0}", g.RegirsterR0);
    }
}

Wrok the same and easer to read.

Piotr Knut
  • 350
  • 3
  • 8
  • I think he forgot a *bit* more than that; such as a basic understanding of properties. It is important that its in a method though! – BradleyDotNET Nov 11 '14 at 00:57
  • I am a long time I used Visual Basic and a few years ago I switched to C #. Often I had a problem with it. It is always difficult in the beginning. – Piotr Knut Nov 11 '14 at 01:16