another newbie question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,
I'm familiar with the use of the dot operator to access properties of
instantiated classes, as well as declaring objects of classes (such as the
following):

SomeClass object1 = new SomeClass();
object1.SomeProperty = Somevalue;

But consider the following I recently came across:

CustomVertex.TransformedColored[] verts = new
CustomVertex.TransformedColored[3];

I believe that the author of this code is declaring a fixed-size array of
"TransformedColored" structures...what I find confusing is the dot-operator
indirection. "CustomVertex" is the name of a class type - no objects have
been instantiated, and yet we can declare variables of the types containd
within that class? In other words, does the CustomVertex class code look
like this (?):

public class CustomVertex {
..
..
public struct TransformedColored{
..
}
}

Could someone explain/describe what that line of code is actually doing? I
hope this question hasn't been too confusing. Thanks in advance everyone!
 
It is not necessary to create an instance of class "A" before creating an
instance of class "A.B". In my example below each line of code in the Main()
method is valid on its own, without the other lines being present.


Lionel said:
Thanks KH,

but you're instantiating an object of type "A", and then using that object
to instantiate another object of type "B". Part of my confusion lies in the
fact that the "CustomVertex" class in my example wasn't instantiated. I
don't believe it is a namespace since the documentation lists it as a class
type in the Microsoft.DirectX.Direct3D namespace. So...how can I declare a
type within a class without instantiating that class first (as you have done)?

Or maybe I'm just thinking about this too much?

KH said:
As you speculate, "TransformedColored" is a type declared within the type
"CustomVertex" (you state CustomVertex is a type not a namespace, correct?)

So for example:

namespace ns
{
class A
{
class B { };
};

static void Main()
{
ns.A a = new ns.A(); // Create an instance of the "A" type
ns.A.B b = new ns.A.B(); // Create an instance of the "B" type, which
is declared within "A"

ns.A.B[] array = new ns.A.B[3]; // Create an array of "B" objects
}

};



Lionel said:
Hello all,
I'm familiar with the use of the dot operator to access properties of
instantiated classes, as well as declaring objects of classes (such as the
following):

SomeClass object1 = new SomeClass();
object1.SomeProperty = Somevalue;

But consider the following I recently came across:

CustomVertex.TransformedColored[] verts = new
CustomVertex.TransformedColored[3];

I believe that the author of this code is declaring a fixed-size array of
"TransformedColored" structures...what I find confusing is the dot-operator
indirection. "CustomVertex" is the name of a class type - no objects have
been instantiated, and yet we can declare variables of the types containd
within that class? In other words, does the CustomVertex class code look
like this (?):

public class CustomVertex {
.
.
public struct TransformedColored{
.
}
}

Could someone explain/describe what that line of code is actually doing? I
hope this question hasn't been too confusing. Thanks in advance everyone!
 
Back
Top