Variables in C# and VFP

C#

public, private

VFP

Local, Private, Public

C# Syntax Notes

C# is strongly typed and every variable must be defined as being of a known type before it can be used. It is also more strongly object-oriented than Visual FoxPro and doesn't have variables existing independently of classes and objects. A private variable which exists inside an object will typically be exposed as a public property with code like this:

class Customer
{
  // Private member variables
  private string cust_id;
  private string company;

  // Properties
  public string Cust_id
  {
    get { return cust_id; }
    set { cust_id = value; }
  }
  public string Company
  {
    get { return company; }
    set { company = value; }
  }
}

This is the simplest of examples. In reality, both the getter and setter methods might process the data or restrict access to their values.

Note that the private variable "cust_id" and the public property "Cust_id" have different capitalisation and refer to two different things. C# is case-sensitive.

VFP Syntax Notes

Visual FoxPro has none of this protection. All variables are of the same general type and you can even change the type of data stored in a variable after it has been used. If you assign a value to a variable without having declared it then that variable will immediately be created and be given Private scope.

Variable scope

Both languages apply scope to variables. Visual FoxPro has a simple system of scope:

  • Public variables are visible throughout the application.
  • Private variables are visible in every module called from the one in which they are declared.
  • Local variables are visible in the module in which they are declared.

FoxPro supports object-oriented and procedural code so the term 'module' above might be a program, procedure, function or method.

Constants  |  Language index  |  Arrays