Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

As a variant of Alex Humphrey's solution Alex Humphrey's solution, You could try this for improved performance:

var properties = new Object[]
{
 this.BlockType, // 1, A_NAME
 this.Tag, // 2, A_TAG
 this.Description, // 3, A_DESC
 this.InitialScan, // 4, A_ISCAN
 this.AutoManual, // 5, A_SCAN
 this.ScanTime, // 6, A_SCANT
 this.IoDevice, // 7, A_IODV
 this.IoAddress, // 8, A_IOAD
 this.InitialAmStatus, // 9, A_IAM
 this.AlarmPriority, // 10, A_PRI
 this.AlarmEnable, // 11, A_ENAB
 this.EnableOutput, // 12, A_EOUT
 this.HistDescription, // 13, A_HIST_DESC
 this.SecurityArea1 // 14, A_SECURITYAREA1
};
var builder = new StringBuilder(properties.Length * 6);
foreach (var property in properties)
{
 builder.Append('"').Append(property).Append('"').Append(',');
}
builder.Remove(builder.Length - 1, 1); // remove the last comma
return builder.ToString();

But beware that this code is susceptible for failure if any of the properties contains a double quote. You should make sure they are escaped.

As a variant of Alex Humphrey's solution, You could try this for improved performance:

var properties = new Object[]
{
 this.BlockType, // 1, A_NAME
 this.Tag, // 2, A_TAG
 this.Description, // 3, A_DESC
 this.InitialScan, // 4, A_ISCAN
 this.AutoManual, // 5, A_SCAN
 this.ScanTime, // 6, A_SCANT
 this.IoDevice, // 7, A_IODV
 this.IoAddress, // 8, A_IOAD
 this.InitialAmStatus, // 9, A_IAM
 this.AlarmPriority, // 10, A_PRI
 this.AlarmEnable, // 11, A_ENAB
 this.EnableOutput, // 12, A_EOUT
 this.HistDescription, // 13, A_HIST_DESC
 this.SecurityArea1 // 14, A_SECURITYAREA1
};
var builder = new StringBuilder(properties.Length * 6);
foreach (var property in properties)
{
 builder.Append('"').Append(property).Append('"').Append(',');
}
builder.Remove(builder.Length - 1, 1); // remove the last comma
return builder.ToString();

But beware that this code is susceptible for failure if any of the properties contains a double quote. You should make sure they are escaped.

As a variant of Alex Humphrey's solution, You could try this for improved performance:

var properties = new Object[]
{
 this.BlockType, // 1, A_NAME
 this.Tag, // 2, A_TAG
 this.Description, // 3, A_DESC
 this.InitialScan, // 4, A_ISCAN
 this.AutoManual, // 5, A_SCAN
 this.ScanTime, // 6, A_SCANT
 this.IoDevice, // 7, A_IODV
 this.IoAddress, // 8, A_IOAD
 this.InitialAmStatus, // 9, A_IAM
 this.AlarmPriority, // 10, A_PRI
 this.AlarmEnable, // 11, A_ENAB
 this.EnableOutput, // 12, A_EOUT
 this.HistDescription, // 13, A_HIST_DESC
 this.SecurityArea1 // 14, A_SECURITYAREA1
};
var builder = new StringBuilder(properties.Length * 6);
foreach (var property in properties)
{
 builder.Append('"').Append(property).Append('"').Append(',');
}
builder.Remove(builder.Length - 1, 1); // remove the last comma
return builder.ToString();

But beware that this code is susceptible for failure if any of the properties contains a double quote. You should make sure they are escaped.

Source Link
Hosam Aly
  • 1.3k
  • 1
  • 10
  • 13

As a variant of Alex Humphrey's solution, You could try this for improved performance:

var properties = new Object[]
{
 this.BlockType, // 1, A_NAME
 this.Tag, // 2, A_TAG
 this.Description, // 3, A_DESC
 this.InitialScan, // 4, A_ISCAN
 this.AutoManual, // 5, A_SCAN
 this.ScanTime, // 6, A_SCANT
 this.IoDevice, // 7, A_IODV
 this.IoAddress, // 8, A_IOAD
 this.InitialAmStatus, // 9, A_IAM
 this.AlarmPriority, // 10, A_PRI
 this.AlarmEnable, // 11, A_ENAB
 this.EnableOutput, // 12, A_EOUT
 this.HistDescription, // 13, A_HIST_DESC
 this.SecurityArea1 // 14, A_SECURITYAREA1
};
var builder = new StringBuilder(properties.Length * 6);
foreach (var property in properties)
{
 builder.Append('"').Append(property).Append('"').Append(',');
}
builder.Remove(builder.Length - 1, 1); // remove the last comma
return builder.ToString();

But beware that this code is susceptible for failure if any of the properties contains a double quote. You should make sure they are escaped.

lang-cs

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