473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use flags enum as replacement for missing c# 'in'-operator

This is actually an answer to an old post which is closed. But it may nevertheless be useful to someone.

Old Post: Has if () syntax of C# no IN operator like Pascal or SQL (IN, LIKE,BETWEEN)?

Good, short and fast possibility is to define the enum as flags, like e.g.:

Expand|Select|Wrap|Line Numbers
  1. [Flags]
  2. internal enum TokenType
  3. {
  4.     Empty = 0,
  5.     LBrace = 1,
  6.     PlusLBrace = 2,
  7.     RBrace = 4,
  8.     LBracket = 8,
  9.     RBracket = 16,
  10.     Period = 32,
  11.     RecordID = 64,
  12.     Rubbish = 128,
  13.  
  14.     TermStartSymbols = RecordID | LBrace | PlusLBrace | LBracket 
  15. }
You can then test for a flag like this:

Expand|Select|Wrap|Line Numbers
  1. while ((CurrentToken.Type & TokenType.TermStartSymbols) != TokenType.Empty) {
  2.     sequence.Add(Term());
  3. }
Note that TokenType.Empty must be defined as 0.
Mar 23 '11 #1
0 1190

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: threepins | last post by:
Hi, Trying the following ... function getCurrentVal(poValue) { var lcCurrentVal = 0; if (isNaN(parseInt(poValue))) { var loValue = poValue.toUpperCase();
5
by: Woon Kiat | last post by:
Hi, Using IDL, I can declare my enumeration like following, library MyAppLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); typedef enum MyColor
13
by: tmartsum | last post by:
I am not an expert on C++(/C), but also not a complete beginner. I was writing a faster cos (and sin) approximation based on precalculated data (with some success) when I discovered that going...
8
by: Craig Klementowski | last post by:
All, I've installed the VS 2005 Beta 1 and was trying to build our current product. I get a compile error when enum value is specified with classname::enumname::enumvalue. Seems the compiler...
7
by: Inga2005 | last post by:
I have developed an web site in VS2005 but I can't build a release version since the option is missing in the configuration manager. The second thing is that there isn't a bin folder placed in my...
2
by: fritz-bayer | last post by:
Hi, in a shell script of mine I'm executing a mysql SELECT in batch mode. I want to use the return value for other sql statements. The problem I'm facing is that the tabs, which seperate the...
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
18
by: Vic Spainhower | last post by:
Hello, Can someone tell me why on some computers the following list will fail . I have a user reported that some of the links in the below list will fail and some will work. The ones that fail...
1
by: Francesco Moi | last post by:
Hi. I get this error message on my Firefox Error Console: ---------------- Error: missing } in XML expression Source File: http://www.foo.com/js/maps.js Line: 273, Column: 18 Source Code:...
1
by: oracle newbie | last post by:
select student,trunc(hour,'mm') as period,sum(attempts) as attemptsfrom library_website_users a join library_website_stats b using (student_id)where trunc(hour,'yyyy') =...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.