并非所有的代码路径都返回值
namespace netmac
{
class Program
{
static string netmac() {
object netmac;
string st = "";
ManagementObjectSearcher Wmi = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
foreach (ManagementObject WmiObj in Wmi.Get())
{
if (Convert.ToBoolean(WmiObj["IPEnabled"]))
{
System.Array ar;
ar = (System.Array)(WmiObj.Properties["IPAddress"].Value);
st = ar.GetValue(0).ToString();
Debug.WriteLine("IP(" + st + ")|" + "MAC(" + WmiObj["MACAddress"] + ")" + "\n");
netmac = WmiObj["MACAddress"];
netmac = netmac.ToString().Replace(":", "");
return netmac.ToString();
}
}
}
static void Main(string[] args)
{
Console.WriteLine(netmac());
}
}
}
出现错误了: 并非所有的代码路径都返回值
请问遇上这种问题,应该如何解决,新手上路......
C#
并非所有的代码路径都返回值
------解决方案--------------------可以string netmac = "";