Craigt
Craigt

Reputation: 3580

What is this type of member called

I have a simple question. What do you call the MyField variable defined in MyClass below. I'm looking for answers like: "field", "Property", "Instance variable", "Class variable". What would be the most accurate name for it?

public class MyClass
{
    private object MyField;

    ...
}

Upvotes: 0

Views: 68

Answers (2)

David Grayson
David Grayson

Reputation: 87376

It looks like they are called fields:

http://msdn.microsoft.com/en-us/library/aa645750(v=vs.71).aspx

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1499760

It's not a property - it's definitely a field, and it's also an instance variable. From section 10.5.1 of the C# spec:

When a field declaration includes a static modifier, the fields introduced by the declaration are static fields. When no static modifier is present, the fields introduced by the declaration are instance fields. Static fields and instance fields are two of the several kinds of variables supported by C#, and at times they are referred to as static variables and instance variables.

I've never been keen on the terminology "class variable" - it's not clear whether that means instance variable or static variable, and it's also unclear how it applies if you declare it as a member of a value type.

See section 10.5 of the C# 5 specification for more details about fields in general.

Upvotes: 5

Related Questions