#在C#中定义 [英] #define in c#
本文介绍了#在C#中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我在c
中有此代码
#define WINDOWS
#ifdef WINDOWS//在C中,但是在C#中我写了#if WINDOWS
#define bool char
#define假0
#define true 1
#endif
//默认顺序为4.
#define DEFAULT_ORDER 4
我想将其转换为C#.我在使用System之前就把这些定义放了进去.但我仍然面临一个问题.如何在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
推荐答案
#define是C#中的预处理程序指令,您可以看到这里 [
#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 keywordconst
is already there to take a good care of constant values.
我认为您需要确定是否要用C或C#编写.如果您决定使用C#,请不要尝试使用C,因为它们是不同的语言!
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!
C#是C#,而不是C ++.为什么要在C#代码之前放C ++代码?
这些行在C#中都没有任何意义.
只是不要做,要开心. ;)
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. ;)
这篇关于#在C#中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文