sa
sa

Reputation:

need an example of a get and set

Can you give an example of how to use the get and set? I need to call the get method in my code but inorder to do that it needs to be set first by evaluating it everytime.

Ex:

private static string _formatStr = Product == "test" ? "something": "other";
public static string GetFormatStr

{

get { return _formatStr; }

}

So I need this to be set before I call the get method everytime. Call set first and then call get.

Upvotes: 0

Views: 720

Answers (3)

Richard Anthony Hein
Richard Anthony Hein

Reputation: 10650

Please read the C# Language Specification or something.

Upvotes: 0

manji
manji

Reputation: 47978

public static string GetFormatStr
{
    get { return Product == "test" ? "something": "other"; }
}

Upvotes: 0

Frederik Gheysels
Frederik Gheysels

Reputation: 56934

So, you mean that you want this :

public static string FormatStr
{
    get
    {
         return Product == "test" ? "something" : "other";
    }
}

Upvotes: 7

Related Questions