Solved

How to define or declare a hex variable?

Posted on 2006-11-21
4
1,358 Views
Last Modified: 2008-02-07
How and where do I define the followig in C#?

#define UF_ACCOUNTDISABLE 0X2
0
Comment
Question by:lapucca
  • 3
4 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 17990308

int UF_ACCOUNTDISABLE = 0x2;

 or

int a = 0x2F;
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17990309

int UF_ACCOUNTDISABLE = 0x2;

 or

int a = 0x2F;
0
 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 200 total points
ID: 17990310

int UF_ACCOUNTDISABLE = 0x2;

 or

int a = 0x2F;
0
 
LVL 7

Accepted Solution

by:
mjmarlow earned 300 total points
ID: 17990751
C# does not support #define constants.  Instead you create const variable.  The const variables are resolved at compile time.  You can define them anywhere.  


// Example: Create a class GlobalConstants and define a public const variable inside to create global constants

using System;
using System.Collections.Generic;
using System.Text;

namespace BusinessLayer
{
    public class GlobalConstants
    {
        public  const int UF_ACCOUNTDISABLE = 0x2;
    }
}

Reference it in other classes using
...
Console.WriteLine(BusinessLayer.GlobalConstants.ACCOUNTDISABLE);

When this is compiled, the compiler will replace the above statement with:
Console.WriteLine(0x2);

- Mark
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now