Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7598091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:19:18+00:00 2026-05-30T22:19:18+00:00

class constType { public static const Type messageType = typeof(int); // HOW TO DO

  • 0
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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:19:19+00:00Added an answer on May 30, 2026 at 10:19 pm

    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.

    class constType<T> where T : struct
    {
        public T GetT()
        {
            return new T();
        }
    
        public string[] GetArraySomehow()
        {
            var len = Marshal.SizeOf(typeof(T));
            return new string[len];
        }
    }
    
    class testTypeInClass
    {
        public void test<T>(T message) where T : struct
        {
    
        }
    }
    
    class MyClass
    {
        void Test()
        {
            var constType = new constType<int>();
    
            var typeInClass = new testTypeInClass();
    
            var t = constType.GetT();
    
            typeInClass.test(t);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class A { public static void main(String[] args) { A a = new A();
class ZiggyTest{ public static void main(String[] args){ RunnableThread rt = new RunnableThread(); Thread t1
So I have a FileReader class, it looks like this: #define DISALLOW_COPY(type) \ type(const
We have some code that looks like this: class Serializer { public: template<class Type>
class base{ public $c = 'c'; public $sub = ''; function __construct(){ $this->sub =
class binaryOperators { public: int i; binaryOperators (int tempI = 0) { i =
// class class MyClass { public: void doIt() const { cout << It works!
class foo { public readonly int bar; }; foo a = new foo() {
class X { private: string DATA; . . . const string read_entry( const string
class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.