'我是 C# 的新手,通常我的强项是 C++ 和 VB。我有 2 个问题,我对代码发表了评论:
1.) 蓝色波浪线出现在 3 Uses it say ""一个 using namespace 指令只能应用于命名空间;'系统.对象' ...“
2.) 我无法从我声明为公共的变量 LocalIP 中获取输出 IP 地址。
提前致谢。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
//Blue squiggly line appear on this 2 Uses
using Dns = System.Net.Dns;
using AddressFamily = System.Net.Sockets.AddressFamily;
namespace WindowsFormsApplication1
{
public partial class frm_Log : Form
{
public String localIP;
public string LocalIPAddress()
{
IPHostEntry host;
//string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
break;
}
}
return localIP;
}
....
....
// variable localIP.Trim() does not giveout any output
MyValue="LogAccept,"+this.txt_UserName.Text.Trim()+","+this.txt_Password.Text.Trim() + "," + localIP.Trim() ;
....
....