gpt4 book ai didi

c# - 如何声明公共(public)静态字节?

转载 作者:行者123 更新时间:2023-12-03 20:32:51 25 4
gpt4 key购买 nike

我有一个类名常量,我将所有常量值放入我的项目中。我还在检查服务器是否可以在我的整个项目中访问。我想在我的常量中声明一个 IP 地址,这样我只需更改一个并在我的项目中实现它。我不知道如何在常量类中声明该值。我需要的是以下内容:

var ping = new Ping();
var reply = ping.Send(new IPAddress(Constants.ipaddress), 1500);

//I want to change 192,168,120,10 in the value in my constants
var ping = new Ping();
var reply = ping.Send(new IPAddress(new byte[] { 192, 168, 120, 10 }), 1500);

//What I declared in my constants
public static byte ipaddress;

最佳答案

好吧,你可以

public static readonly byte[] ipaddress = new byte[] { 192, 168, 120, 10 };

var ping = new Ping();
var reply = ping.Send(new IPAddress(ipaddress), 1500);

但是,我鼓励您使用app.config来获取此信息。这样,您就可以更改地址,而无需重建项目。如果您选择这样做,请以标准点分四组格式(“192.168.120.10”)存储地址并使用 IPAddress.Parse .

关于c# - 如何声明公共(public)静态字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53330412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com