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 7762333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:22:26+00:00 2026-06-01T14:22:26+00:00

If you have a macro like this in C: #define SLICE_VERSION 20110614 How to

  • 0

If you have a macro like this in C:

 #define SLICE_VERSION 20110614

How to use this macro in C# Script?

Should I marshal it? How?

Should I re-define it in C#? I know C# does not have #define macro but maybe I can just define it as a static variable.

Or can I refer to it somehow?

Similarly, if you have a global variable in C, how do you use it in C# script?

I have seen tutorials about marshaling classes, structures, arrays, unions and lots of other things from C/C++ to C#, but I haven’t been able to find any hint about how marshal a constant… Or do I have to marshal it? Can it be referred to directly?

BTW, I found this a pretty good tutorial about interopping on Mono: http://www.mono-project.com/Interop_with_Native_Libraries#Introduction

  • 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-06-01T14:22:28+00:00Added an answer on June 1, 2026 at 2:22 pm

    Should I re-define it in C#?

    Yes. In C#, you’d want to use a const:

    const int SLICE_VERSION = 20110614;
    

    That being said, I’ll often rename this to make it more C#-standard, as well:

    const int SliceVersion = 20110614;
    

    Depending on how it’s being used, you make wish to specify an access modifier explicitly, as well. Also, depending on the usage, you may want to use a different type (Int32 may not be correct – you may want UInt32, etc.). One disadvantage to macros in C/C++ is that they are not strongly typed, so without seeing the usage, there is no way to know the exact type expected here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR)
Say I have a macro like this: #define SET_TYPE_NAME(TYPE, NAME) \ template<typename T> \
I have macro like this: #define error_exit(format, ...) \ error_at_line(EXIT_FAILURE, 0, __FILE__, __LINE__, format,
I'm having a macro like this ( not exactly, but function is quite equivalent):
I have a macro defined in C something like this: #define SOME_FIELD(_A_,_B_,_C_) \ MyObj[
We have a macro for error-checking that goes like this: #define CheckCondition( x )
I have a macro like this: #define SHOW_EXPR(x) printf (%s=%d\n, #x, (x)) It works:
I have a macro definition in header file like this: // header.h ARRAY_SZ(a) =
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I have an application that used Macro. In this macro I would like to

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.