Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

This should be considered an extension to ChrisWue's answer which discusses IDisposable objects and appropriate method naming.

objNewIP["IPAddress"] = new string[] { "110.110.110.1" };

Has a couple of problems, there is a 'magic number' which we can live with if it must be hardcoded, although it would be better coming from a configuration file or setting. The bigger problem is that unless you are an employee of HEXIE Information technology Co., Ltd who own that address block then stick to assigning to number ranges reserved for 'private use' like 192.168.0.0/16 10.0.0.0/8 for example which give more than enough scope.

if (!(bool) objMO["IPEnabled"]) {

Is there a way to refactor this to make it clearer?

Looking at the performance issue you have invoking EnableStatic you might want to look at StackOverflow: Problems using the WMI EnableStatic method StackOverflow: Problems using the WMI EnableStatic method

This should be considered an extension to ChrisWue's answer which discusses IDisposable objects and appropriate method naming.

objNewIP["IPAddress"] = new string[] { "110.110.110.1" };

Has a couple of problems, there is a 'magic number' which we can live with if it must be hardcoded, although it would be better coming from a configuration file or setting. The bigger problem is that unless you are an employee of HEXIE Information technology Co., Ltd who own that address block then stick to assigning to number ranges reserved for 'private use' like 192.168.0.0/16 10.0.0.0/8 for example which give more than enough scope.

if (!(bool) objMO["IPEnabled"]) {

Is there a way to refactor this to make it clearer?

Looking at the performance issue you have invoking EnableStatic you might want to look at StackOverflow: Problems using the WMI EnableStatic method

This should be considered an extension to ChrisWue's answer which discusses IDisposable objects and appropriate method naming.

objNewIP["IPAddress"] = new string[] { "110.110.110.1" };

Has a couple of problems, there is a 'magic number' which we can live with if it must be hardcoded, although it would be better coming from a configuration file or setting. The bigger problem is that unless you are an employee of HEXIE Information technology Co., Ltd who own that address block then stick to assigning to number ranges reserved for 'private use' like 192.168.0.0/16 10.0.0.0/8 for example which give more than enough scope.

if (!(bool) objMO["IPEnabled"]) {

Is there a way to refactor this to make it clearer?

Looking at the performance issue you have invoking EnableStatic you might want to look at StackOverflow: Problems using the WMI EnableStatic method

Source Link

This should be considered an extension to ChrisWue's answer which discusses IDisposable objects and appropriate method naming.

objNewIP["IPAddress"] = new string[] { "110.110.110.1" };

Has a couple of problems, there is a 'magic number' which we can live with if it must be hardcoded, although it would be better coming from a configuration file or setting. The bigger problem is that unless you are an employee of HEXIE Information technology Co., Ltd who own that address block then stick to assigning to number ranges reserved for 'private use' like 192.168.0.0/16 10.0.0.0/8 for example which give more than enough scope.

if (!(bool) objMO["IPEnabled"]) {

Is there a way to refactor this to make it clearer?

Looking at the performance issue you have invoking EnableStatic you might want to look at StackOverflow: Problems using the WMI EnableStatic method

lang-cs

AltStyle によって変換されたページ (->オリジナル) /