class constType
{
public static const Type messageType = typeof(int); // HOW TO DO THIS? 1st mark
public string[] GetArraySomehow()
{
return new string[sizeof(messageType)]; // HOW TO DO THIS? 2nd mark
}
}
class testTypeInClass
{
public void test(constType.messageType message) // HOW TO DO THIS? 3rd mark
{
}
}
Okay so this is really weird and strange I know but how can I do this?
- 1st mark: I have to store int’s type as const variable and use it laterç
- 2nd mark: I have to get stored type’s size (how many bytes does it equal?)
- 3rd mark: I have to use it as a parameter type.
Well Why I have to do this such thing:
I have to store a type (not so wide, just I know I’ll use int8,16,32 etc)
and have to know what exactly bytes does it equal (1,2,4 etc..);
well first of all I have a method in one of my classes which uses switch statement and:
like this:
public string test (int messageIndex)
{
switch (messageIndex)
{
case 0:
return "etc.. etc..";
case 1231412:
return "whatever";
}
}
Firstly I had some method like this:
public int fixForSwitchStatement(byte[] messageIndex)
{
byte[] RValue = new byte[4];
for (int i = 0; i <= messageIndex.Length - 1; i++)
{
RValue[i] = messageIndex[i];
}
for (int i = messageIndex.Length; i <= 4 - messageIndex.Length - 1; i++)
{
RValue[i] = 0;
}
return BitConverter.ToInt32(RValue, 0);
}
I was passing byte or short to switch statement then I was converting to int (int was a specified type for me) and I wanted to make a redesign like this.
public string test (/* [what's the case limit? that I've determined?] */ messageIndex)
{
switch (messageIndex)
{
case 0:
return "etc.. etc..";
case 1231412:
return "whatever";
}
}
Because I don’t want to use fixSwitch… method anymore. I just need a specified type for all of these concept.
Why I have to use fixSwitch instead of typecasting like (int)somethingByte?
Well in my one of classes there is a thing called communicationSize, its the messageIndex thing’s maximum size in byte(s) that I have to declare. This is for my server-client project. There is a messageIndex thing being used as a request index what server and client requests from each other. And I’m limiting it with byte(s). For save some data space from connection.
// still is being written
I’m not sure what the goal is and the question has been edited in the meantime but heres some example code using generics that may help you further.