Alan2
Alan2

Reputation: 24572

In a Xamarin application how should I set up constants?

Here's what I am doing right now:

public static class CONST
{
    public static bool CarTmr = false;

Is this another way to do this that is more commonly used?

Upvotes: 0

Views: 134

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26430

I'd go with the Microsoft recomended way

static class Constants
{
    public const double Pi = 3.14159;
    public const int SpeedOfLight = 300000; // km per sec.
}

// Accessible like
double area = Constants.Pi * (radius * radius);

So in your case:

public static class CONST
{
    public const bool CarTmr = false;
}

Depending on the situation, you could also setup a class that reads from the configuration, if those constants relate to runtime and might be changed in the future.

There is no Xamarin specific, better way to achieve it.

Upvotes: 1

Related Questions