Good day.
I have a problem declaring new string value with the value came from textbox1.text and the value of the textbox is 192.168.1.5 this is the code which is not working.
newIP["SubnetMask"] = new String[] { textBox1.Text };
Now i have string sampleip that i declared
string sampleip = "192.168.1.5";
newIP["SubnetMask"] = new String[] { sampleip };
that code is working.
but the question is.
how the code works fine if the codes will be this one
newIP["SubnetMask"] = new String[] { textBox1.Text };
i will show you guys the whole code.
// this code for ip and subnet
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters("EnableStatic");
string sampleip = "192.168.1.5";
**newIP["SubnetMask"] = new String[] { textBox1.Text };**
newIP["IPAddress"] = new String[] { textBox2.Text };
setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
this is the value in my textbox1.text i have sample image here sample output
thanks guys.