Creating a new instance of a class

Typically, you define a class, and then create one or more instances of that class. An instance of a class is also known as an object. Each instance has its own set of associated data. The process of constructing a new instance is called instantiating a class. To instantiate a class, use the new operator:

var e = new smithco.messaging.QueueUtils()  // Instantiate a new instance of QueueUtils.

You can use object initializers to set properties on an object immediately after a new expression. Use object initializers for compact and clear object declarations. Object initializers are especially useful in combination with data structure syntax and nested objects. A simple use of an object initializer looks like the following line:

var sampleClaim = new Claim() {:ClaimId = "TestID"}  // Initialize the ClaimID on the new claim.
Note: You can use static methods, static variables, and static properties of a Gosu class without creating an instance of the class.

See also