what does the term 'state data' mean?

G

garyusenet

In a book i'm reading i've just ventured into chapter 3 - C# language
fundamentals.
Now i can see that the first part of the code after the class
definition defines a public variable, of type string, called
userMessage. But I don't understand the term 'point of state data' can
someone clarify that for me please.

TIA. Gary-

I've just encountered the following sample code: -

// HelloClass, with constructors.
using System;
class HelloClass
{
// A point of state data.
public string userMessage;

// Default constructor.
public HelloClass()
{ Console.WriteLine("Default ctor called!"); }

// This custom constructor assigns state data
// to a user-supplied value.
public HelloClass (string msg)
{
Console.WriteLine("Custom ctor called!");
userMessage = msg;
}

// Program entry point.
public static int Main(string[] args)
{

// Call default constructor.
HelloClass c1 = new HelloClass();
Console.WriteLine("Value of userMessage: {0}\n", c1.userMessage);

// Call parameterized constructor.
HelloClass c2;
c2 = new HelloClass("Testing, 1, 2, 3");
Console.WriteLine("Value of userMessage: {0}", c2.userMessage);
Console.ReadLine();
return 0;
}
}
 
G

Guest

I think it should say a 'piece' of state data. State data is a term for
pieces of information held in variables in an instance of a object. Together
all these pieces of information constitute the current 'state' of the object.
 
D

Dave Sexton

Hi Gary,

"State" is data that is persisted for the lifetime of an instance of an
object (although "state" can also be "static", which means it's shared by
every instance of a class). In other words, when you set the "userMessage"
field its value will remain the same until its either changed or the object
is collected by the GC.

I've never heard of the phrase "point of state", however.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top