如何从中获取Internet协议版本4地址Dns.GetHostAddresses()?我有下面的代码,它给我IPv4和IPv6地址.我必须使用具有多个IPv4地址的盒子.
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
private void get_IPs()
{
foreach (IPAddress a in localIPs)
{
server_ip = server_ip + a.ToString() + "/";
}
}
Run Code Online (Sandbox Code Playgroud) 如何在app.config中获取数组或列表信息?我希望用户能够尽可能多地放置IP(或根据需要).我的程序只需要在app.config中指定的任何内容.这该怎么做?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ip" value="x" />
<add key="ip" value="y" />
<add key="ip" value="z" />
</appSettings>
</configuration>
public string ip = ConfigurationManager.AppSettings["ip"];
Run Code Online (Sandbox Code Playgroud) 可能重复:
在C#中忽略异常
有时在极少数情况下你真的想忽略异常.做这个的最好方式是什么?我的方法是抓住异常,但不做任何事情.其他?
try
{
blah
}
catch (Exception e)
{
<nothing here>
}
Run Code Online (Sandbox Code Playgroud) 我通常使用文本文件作为配置.但是这次我想利用app.config将文件名(密钥)与名称(值)相关联,并在组合框中使名称可用
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Scenario1.doc" value="Hybrid1"/>
<add key="Scenario2.doc" value="Hybrid2"/>
<add key="Scenario3.doc" value="Hybrid3"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这会有用吗?如何检索数据?
我想逐步检查流程的标准输出.在读取第二行后,myProcess.StandardOutput.EndofStream从false变为true.因此它从while循环退出.也许我应该用别的东西?
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = my_command;
myProcess.StartInfo.Arguments = " "+ location;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
while (!myProcess.StandardOutput.EndOfStream)
{
string standard_output = myProcess.StandardOutput.ReadLine();
if (standard_output.Contains("xx"))
{
//do something
break;
}
}
myProcess.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud) perfmon计数器使用不同的NIC名称与ipconfig/all和c#系统调用相比,如下所示(这是来自ipconfig/all)
Run Code Online (Sandbox Code Playgroud)Ethernet adapter HHHH: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : HP NC364T PCIe Quad Port Gigabit Server Adapter #3 Physical Address. . . . . . . . . : 00-1F-29-0D-26-59 DHCP Enabled. . . . . . . . . . . : No Autoconfiguration Enabled . . . . : Yes IPv4 Address. . . . . . . . . . . : 166.49.47.10(Preferred) Subnet …
我有一个哈希表,其中键是字母键,值是数字键.如何根据键对哈希表进行排序?
ExchangeA, 200
ExchangeV, 100
ExchangeC, 200
Run Code Online (Sandbox Code Playgroud)
就像这样
ExchangeA, 200
ExchangeC, 200
ExchangeV, 100
Run Code Online (Sandbox Code Playgroud) <?xml version="1.0" encoding="ISO-8859-1"?>
<kdd>
<Table>
<robel ID="1">
<groof NAME="GOBS-1">
<sintal ID="A">Cynthia1</sintal>
<sintal ID="B">Sylvia2</sintal>
<sintal ID="C">Sylvia3</sintal>
<sintal ID="D">Sylvia4</sintal>
</groof>
<groof NAME="GOBS-2">
<sintal ID="A">Cynthia1</sintal>
<sintal ID="B">Cynthia2</sintal>
<sintal ID="C">Cynthia3</sintal>
<sintal ID="D">Cynthia4</sintal>
</groof>
<groof NAME="GOBS-3">
<sintal ID="A">Daniella1</sintal>
<sintal ID="B">Daniella2</sintal>
<sintal ID="C">Daniella3</sintal>
<sintal ID="D">Daniella4</sintal>
</groof>
</robel>
</Table>
</kdd>
Run Code Online (Sandbox Code Playgroud)
我想得到GOBS-2的Cynthia1.注意GOBS-1还有另一个Cynthia1
foreach (XElement element in doc.Descendants("groof"))
{
string mmname = element.Attribute("NAME").Value.ToString();
if (mmname == "GOBS-2")
{
bool found = false;
foreach (XElement element1 in doc.Descendants("sintal"))
{
if (found == false)
{
string CurrentValue = (string)element1;
if ("Cynthia1" …Run Code Online (Sandbox Code Playgroud) 我想忽略一个空的行,null或只有空格或空格(空格).这里的关键字是多个空格.我试过下面的代码没有成功
if (!string.IsNullOrEmpty(line1))
Run Code Online (Sandbox Code Playgroud)
要么
if (line2 != "")
Run Code Online (Sandbox Code Playgroud)
而且我不想修剪文件因为我想捕捉空间空间abc空间而不是空间空间空间等等谢谢
C#中的软件版本是否有数据类型?我希望能够轻松比较5.02.0002.2和5.02.0003.0(哪一个更高).
c# ×10
.net ×1
.net-3.0 ×1
app-config ×1
config ×1
exception ×1
file ×1
hashtable ×1
ip-address ×1
ipv4 ×1
networking ×1
process ×1
sorting ×1
space ×1
xml ×1