C#获取应用程序版本信息

<span style="font-size:14px;">
</span>
<span style="font-size:14px;">Assembly.GetExecutingAssembly().GetName().Version.ToString();//获取目前應用程式的版本</span>
<span style="font-size:14px;">//获取文件版本信息
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
var fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
string content = fvi.FileVersion;</span>

可以使用 C# 中的 `TcpConnectionInformation` 和 `IPGlobalProperties` 类来获取当前应用程序的网络连接信息。 以下是一个获取当前应用程序的 TCP 连接信息的示例代码: ```csharp using System.Net.NetworkInformation; // 获取当前应用程序的 TCP 连接信息 IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipGlobalProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation tcpConnection in tcpConnections) { Console.WriteLine($"Local endpoint: {tcpConnection.LocalEndPoint}"); Console.WriteLine($"Remote endpoint: {tcpConnection.RemoteEndPoint}"); Console.WriteLine($"State: {tcpConnection.State}"); } ``` 以下是一个获取当前应用程序的 UDP 连接信息的示例代码: ```csharp using System.Net.NetworkInformation; // 获取当前应用程序的 UDP 连接信息 IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); IPEndPoint[] udpListeners = ipGlobalProperties.GetActiveUdpListeners(); foreach (IPEndPoint udpListener in udpListeners) { Console.WriteLine($"Local endpoint: {udpListener}"); } ``` 在上面的示例代码中,我们首先使用 `IPGlobalProperties.GetIPGlobalProperties()` 方法获取一个 `IPGlobalProperties` 对象,然后使用该对象的 `GetActiveTcpConnections()` 和 `GetActiveUdpListeners()` 方法分别获取当前应用程序的 TCP 和 UDP 连接信息。最后,我们可以遍历连接信息并输出相关信息。 请注意,为了使用 `IPGlobalProperties` 类,您需要在代码中包含 `System.Net.NetworkInformation` 命名空间。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值