const typeEnum[] myArray1 = {typeEnum.ship};
Constant Array
Page 1 of 112 Replies - 581 Views - Last Post: 15 August 2012 - 05:21 AM
#1
Constant Array
Posted 08 August 2012 - 07:08 PM
Replies To: Constant Array
#2
Re: Constant Array
Posted 09 August 2012 - 12:22 AM
#3
Re: Constant Array
Posted 09 August 2012 - 07:06 AM
Error 9 'myArray1' is of type '_3DgameTest.typeEnum[]'. A const field of a reference type other than string can only be initialized with null.
#4
Re: Constant Array
Posted 09 August 2012 - 07:52 AM
#5
Re: Constant Array
Posted 09 August 2012 - 09:43 AM
static readonly ArrayItem[] = new ArrayItem[]{Item1, Item2};
#6
Re: Constant Array
Posted 10 August 2012 - 01:42 PM
Also, you mentioned Reference. Which was my next question. How do I declare this in my class variables? I want one class to have references to other classes:
public ref clsObject theShip = null;
The error I am getting:
Quote
#7
Re: Constant Array
Posted 11 August 2012 - 10:18 AM
#8
Re: Constant Array
Posted 11 August 2012 - 12:26 PM
So if you want something to be passed by reference regardless of whether it is a reference type or not do the following:
void modifyValueByReference(ref float valueToBeModified)
{
valueToBeModified++;
}
To use the method:
float myFloat = 0f; modifyValueByReference(ref myFloat);
But when a "Class" is involved it's almost always referenced, sometimes classes can be designed that they don't really follow the rules of reference, like "string" for example each time it's modified a new allocation of memory is created thus updating its reference point which means passing it around by reference is pointless where as when you're passing classes around they are being passed by reference and when you modify 1 value it modifies that block of data referenced by the pointer, unless you make your class setup new memory each time.
As for pointers you may want to read into ptr structures/classes and the com interop services maybe the marshal class aswell
#10
Re: Constant Array
Posted 13 August 2012 - 08:32 AM
racidon, on 11 August 2012 - 03:26 PM, said:
A class is always a reference type. A struct on the other hand is a value type. Most of the base types in C#, like int, float and char, are actually structs, not classes. structs follow most of the same rules as classes but there are some differences. structs can't be inherited for example. string types are classes and their values are placed on the heap and not on the stack. The actual characters of the string are handled differently than most other classes. Check the article below for more reading on the topic of reference vs value types.
http://msdn.microsof...ibrary/ms173109
#11
Re: Constant Array
Posted 13 August 2012 - 09:30 PM
SixOfEleven, on 13 August 2012 - 08:32 AM, said:
racidon, on 11 August 2012 - 03:26 PM, said:
A class is always a reference type. A struct on the other hand is a value type. Most of the base types in C#, like int, float and char, are actually structs, not classes. structs follow most of the same rules as classes but there are some differences. structs can't be inherited for example. string types are classes and their values are placed on the heap and not on the stack. The actual characters of the string are handled differently than most other classes. Check the article below for more reading on the topic of reference vs value types.
http://msdn.microsof...ibrary/ms173109
I'm aware of this, but you can make a class act like string, so although it is reference if you passed the value of a class it would not update the original.
This happens with string because of how the operators are defined, in string they setup a completely new array assigning it a new memory address meaning the original one which is holding address X and now the new one which points to address Y.
This can be achieved with classes, so I was basically trying to say that you can make a class not follow the general rule of reference.
#12
Re: Constant Array
Posted 14 August 2012 - 02:21 PM
#13
Re: Constant Array
Posted 15 August 2012 - 05:21 AM
|
|

New Topic/Question
Reply


MultiQuote







|