Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello
I have this code in c
#define WINDOWS
 
#ifdef WINDOWS// in C but in C# I wrote #if WINDOWS
#define bool char
#define false 0
#define true 1
#endif
 
// Default order is 4.
#define DEFAULT_ORDER 4
 

I want to convert it to C#. I put these definition before using System; but still I am facing a problem.. How can write them in C#
Thanks

#define WINDOWS
#if WINDOWS
#define bool char
#define false 0
#define true 1
#endif
// Default order is 4.
#define DEFAULT_ORDER 4
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
 
Error   1   Single-line comment or end-of-line expected C:\Users\ACER AX3950\AppData\Local\Temporary Projects\ConsoleApplication2\Program.cs    4   14  ConsoleApplication2
 

Error   2   Identifier expected C:\Users\ACER AX3950\AppData\Local\Temporary Projects\ConsoleApplication2\Program.cs    5   9   ConsoleApplication2
Posted 30-Dec-10 18:47pm
Comments
Richard MacCutchan at 31-Dec-10 12:35pm
   
Take the definitions out, they are not needed or wanted in C#, and serve no purpose except to prevent your code from compiling successfully.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

C# is C#, not C++. Why would you ever put C++ code before C# code?
None of those lines make any sense in C#.
 
Just don't do it and be happy. Wink | ;)
  Permalink  
Comments
Espen Harlinn at 28-Feb-11 15:34pm
   
Right, my 5
SAKryukov at 1-Mar-11 3:51am
   
He-he. Thank you, Espen,
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

#define is a preprocessor directives in C#, you can see HERE[^] for more.
 
AFAIK #define in C,C++ used to define constant values, But In C# the keyword const is already there to take a good care of constant values.
  Permalink  
Comments
SAKryukov at 31-Dec-10 11:43am
   
Sure, there is C# define. I did not describe it because using C# define wan not an issue. In the context of the question, no defines are actually needed. But it was nice of you to point out its usage, as well as C# constant.
SAKryukov at 31-Dec-10 11:44am
   
My 5, anyway
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I think you need to decide whether you want to write in C or C#. If you've decided to use C#, then don't try to use C -- they are different languages!
  Permalink  
Comments
SAKryukov at 31-Dec-10 11:48am
   
Good point, my 5.
 
Of course, it can be helpful to master both C++ and C# despite of your advice, but doing it in the same file seems too tricky :-)
Walt Fair, Jr. at 31-Dec-10 11:52am
   
Oh agree that it's nice to know both C and C#, as well as a couple dozen other languages. But as you say, not in the same file.
SAKryukov at 31-Dec-10 12:07pm
   
Even with C++/CLI the author of the question should forget about include files (however, you can develop mixed native/CLI projects) and #define (in almost all cases). (I'm talking about my new answer.)
 
Frankly, even with native C++ development using pre-precessor this is a very bad sign:
"#define DEFAULT_ORDER 4" is pretty bad! Even in C++ one should have used constants. So, before porting C++ to C# the author of the question should consider improving C++ skills.
 
We're talking about mastering two or more languages, but the issue is just one, so far.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I have another idea. Your apparent preoccupation with C++ interferes with your ability to learn C# right now. It happens. Our advices seemingly did not help you -- just yet.
 
Consider alternative: learn to use C++/CLI instead of C#. This way, you start .NET development using some extended C++ dialect, something you may be more comfortable with. When you're more or less comfortable with .NET development, you may or may not need getting to C#.
  Permalink  
Comments
Espen Harlinn at 28-Feb-11 15:38pm
   
C++/CLI - well worth the effort, my 5
SAKryukov at 1-Mar-11 3:52am
   
Thank you, Espen,
--SA

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

  Print Answers RSS
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 31 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100