首页 > 其他分享 >csharp #if #endif 预处理器指令

csharp #if #endif 预处理器指令

时间:2024-01-31 19:11:57浏览次数:20  
标签:info Console endif 指令 处理器 csharp debug

RemoteDesktopConnection\src\Program.cs

#define debug
using System;
using System.Text.RegularExpressions;

namespace RDP
{
    class Program
    {
        static void Main(string[] args)
        {

            var info = new LogInfo();
        #if debug
            Console.WriteLine("please enter ipAddress");
            while (true)
            {
                info.Ipaddress = Console.ReadLine();
                if (new Regex(RdpConstant.IpaddressPatten).IsMatch(info.Ipaddress))
                {
                    break;
                }
            }
            Console.WriteLine("please enter username");
            info.Username = Console.ReadLine();
            Console.WriteLine(info.Username);
            Console.WriteLine("please enter password");
            info.Password = Console.ReadLine();
         #else
            info.Ipaddress = "120";
            info.Username = "Adm";
            info.Password = "wu";
        #endif
            RdpHandler.Rrocess(info);
        }
    }
}



  • # 号开头的代码叫做预处理器指令,它们是编译器的命令,影响编译过程。这些命令指定了哪些代码段要编译或者如何处理特定的错误和警告。C# 预处理器指令以 # (井号) 符号开始,每个预处理器指令只占一行。预处理器指令不需要分号结束,而是用换行符结束。

您的代码中使用了以下几种预处理器指令:

  • define: 用于定义一个符号,例如 #define debug 定义了一个名为 debug 的符号。定义的符号可以用于 #if 指令中的条件编译,如果符号被定义了,那么 #if 指令中的表达式就为真。

  • if: 用于测试一个预处理器表达式是否为真,例如 #if debug 测试 debug 符号是否被定义。#if 指令后面必须跟着一个 #endif 指令。#if 指令中的代码只有在表达式为真时才会被编译。

  • else: 用于和 #if 指令配合,创建复合条件指令,例如 #if debug ... #else ... #endif。#else 指令中的代码只有在 #if 指令中的表达式为假时才会被编译。

  • endif: 用于和 #if 指令配合,表示条件指令的结束,例如 #if debug ... #endif。

您的代码中的预处理器指令的作用是:

  • 如果定义了 debug 符号,那么程序会从控制台读取用户输入的 IP 地址、用户名和密码,并用正则表达式验证 IP 地址的格式是否正确。
  • 如果没有定义 debug 符号,那么程序会使用固定的 IP 地址、用户名和密码。
  • 然后程序会调用 RdpHandler.Rrocess(info) 方法,处理用户的远程桌面连接请求。

总之就是,注释掉上面#define,就会执行#else后面的语句,相当于可以用来跳过一部分代码(#if)的执行

标签:info,Console,endif,指令,处理器,csharp,debug
From: https://www.cnblogs.com/zhuoss/p/17999926

相关文章

  • csharp 远程桌面登录 mstsc rdp文件
    RemoteDesktopConnection\src\LogInfo.csnamespaceRDP{classLogInfo{publicstringIpaddress{get;set;}publicstringUsername{get;set;}publicstringPassword{get;set;}}}RemoteDesktopConnection\src......
  • CSharp: create pdf file using iText 8.0 in donet 8.0
     /*IDE:VS202217.5OS:windows10.net8.0iText8.0System.Text.Encoding.CodePages*/namespaceConsoleAppPdfdemo{usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.IO;usingSystem.Text;......
  • csharp_获取属性的字符串名称
    PropertySupport\Person.cspublicclassPerson{publicstringName{get;set;}publicstringgetPropertyName(){returnPropertySupport.ExtractPropertyName(()=>Name);}}PropertySupport\Program.csPersonperson=newP......
  • CSharp: iText 8.0 in donet 4.8.1
     usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.IO;usingSystem.Text;usingiText.IO.Font;usingiText.IO.Image;usingiText.Kernel.Font;usingiTe......
  • csharp 发布订阅 接口
    event_learn\MyEvent.csnamespaceMyEvent;publicdelegatevoidMyEventHandler(objectsender,EventArgse);//定义一个自定义的事件接口,包含一个事件声明publicinterfaceIMyEvent{//使用event关键字声明一个事件,指定委托类型和事件名称eventMyEven......
  • csharp 发布订阅 传递参数
    event_learn\Program.cs//定义一个派生自EventArgs的自定义类,用于封装数据publicclassMyEventArgs:EventArgs{//定义一个公共的字符串属性,用于存储和获取数据publicDateTime?EmitDate{get;set;}}//定义一个发布者类,它有一个MyEvent事件public......
  • csharp 发布订阅 设计模式
    event_learn\Program.csusingSystem;//定义一个发布者类,它有一个MyEvent事件publicclassPublisher{//声明一个事件,使用EventHandler委托类型publiceventEventHandlerMyEvent;//定义一个触发事件的方法protectedvirtualvoidOnMyEvent()......
  • MT6789(G99)性能参数/datasheet_MTK联发科4G处理器
    联发科MT6789将4G智能手机带入下一代。基于高效率的台积电N6(6nm级)芯片生产工艺,该芯片可全天候实现出色的游戏,加上大摄像头,快速显示,流畅的流媒体和可靠的全球连接。合作伙伴可以定制联发科HelioG99平台,以满足其设备或市场的特定要求。与天玑700相比,MT6789去掉了5G基带。它采用八......
  • 实测分享,瑞芯微RK3588八核国产处理器性能测评!确实“遥遥领先”!
    RK3588处理器优势RK3588是瑞芯微最新一代旗舰工业处理器,它具有如下卓越优势:超强运算能力:四核[email protected]+四核[email protected]大小核架构,有国产“至强嵌入式处理器”之称,可提供高效的计算和多线程处理能力。超强AI算力:6TOPSNPU,支持INT4/INT8/INT16/FP16/BF1......
  • 储迹NAS携3A6000新一代处理器参会龙芯重磅发布会
    11月28日,2023龙芯产品发布暨用户大会在国家会议中心如约启幕。大会以“到中流击水”为主题,现场发布新一代通用处理器龙芯3A6000。储迹作为龙芯的合作伙伴,携最新龙芯CPU3A6000到会议现场展示最新成果。龙芯3A6000处理器采用龙芯自主指令系统龙架构(LoongArch),是龙芯第四代微架构的首款......