Click here to Skip to main content
15,743,299 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have a project of Patient information system.In this project I am using flag attribute but after run my project I am getting the error "the name flag does not exist in current context".
How can i clear this?
plz help me.
Updated 20-Apr-11 19:51pm

This is System.Flags.

Optionally, use

using System;


using Flags = System.Flags;

In the above cases you could omit "System" from "System.Flags".

Remember, this attribute only affect string presentation of the value of your enumeration type, showing bit set properly, for example "DeclaredOnly, Static"; without this attribute it would be "10".

Also, "OptionalParamBinding = 262144" is pretty bad. Use hexadecimal notation for readability, or, better yet, a binary shift:

enum NumericSamples {
   None = 0,
   First = 1 << 0,
   Second = 1 << 1,
   Third = 1 << 2,

For more useful hints and techniques, see my articles:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^],
Human-readable Enumeration Meta-data[^],
Enumeration-based Command Line Utility[^], especially the first one.

Good luck,
Share this answer
GlobX 21-Apr-11 2:12am    
"OptionalParamBinding = 262144" is pretty bad

Good point! My example was from VS opening System.Reflection.BindingFlags from metadata... oops :)
Sergey Alexandrovich Kryukov 21-Apr-11 2:53am    
...Some Microsoft samples suffer from bad readability, and auto-generated code violates Microsoft naming conventions (but it could be uses as a good reason to rename all names to semantically sound ones).
I missed one point, I thought the sample code is from OP, not yours.
Thank you.
Sridharan, some more information and source code would help!

From your question I'm going to blindly guess you are using 'flag' instead of 'Flags', see below:

[Flags] // System.Flags or System.FlagsAttribute will also work.
public enum BindingFlags
    Default = 0,
    IgnoreCase = 1,
    DeclaredOnly = 2,
    Instance = 4,
    Static = 8,
    Public = 16,
    NonPublic = 32,
    FlattenHierarchy = 64,
    InvokeMethod = 256,
    CreateInstance = 512,
    GetField = 1024,
    SetField = 2048,
    GetProperty = 4096,
    SetProperty = 8192,
    PutDispProperty = 16384,
    PutRefDispProperty = 32768,
    ExactBinding = 65536,
    SuppressChangeType = 131072,
    OptionalParamBinding = 262144,
    IgnoreReturn = 16777216,

I'm going to assume you know how flags work and why you would/wouldn't use them :)
Share this answer
Sergey Alexandrovich Kryukov 21-Apr-11 2:04am    
Maybe, but also could be a lack of "using".

Sridharan, don't you use intellisense?! You don't have to type it all manually!
sridharan28 21-Apr-11 2:08am    
How can i add the flag reference
GlobX 21-Apr-11 2:09am    
See SA's solution below (Solution 2)!
See SA's solution above (Solution 1)!

See SA's solution! (haha, thanks for the advice SA - fairly new to the q&a section)
Sergey Alexandrovich Kryukov 21-Apr-11 2:50am    
Just a note: there was a document: not to reference solutions (I guess Questions are fine to reference), because they are re-ordered all the time, and the URLs are also not permanent.
Just don't say "below" or "2".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900