0
\$\begingroup\$

Basically when the code says

public static Camera Instance
{
// Code and something with get statement
}

Is it declaring a method? I don't think it is a method because there is no parenthesis to indicate the area to put in parameters. Here is the full class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ScrollingTest
{
    public class Camera
    {
    private static Camera instance;
    public static Camera Instance
    {
        get
        {
            if (instance == null)
                instance = new Camera();
            return instance;

        }

    }
}
}
\$\endgroup\$
  • \$\begingroup\$ This is solely a C# question by the way, not a game development question. \$\endgroup\$ – dimitris93 Apr 5 '15 at 15:37
2
\$\begingroup\$
public static Camera Instance
{
    get
    {
        if (instance == null)
            instance = new Camera();
        return instance;

    }
}

This is called a Property.

\$\endgroup\$
  • 1
    \$\begingroup\$ And it is static because there is only one camera and it needs to be accessible everywhere. The purpose of this property is to allow read-only access to the private instance. Camera can modify instance, but everyone else can only retrieve it. They have also allowed Camera to initialize the static instance, if/when something first requests it. If the Camera constructor is made private, then Cameras (only one) can only be created through this property. \$\endgroup\$ – Jon Apr 5 '15 at 13:31
  • \$\begingroup\$ And, by adding a set{}, the property becomes read/write. \$\endgroup\$ – Jon Apr 5 '15 at 13:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.