This question is locked. New answers and comments are not allowed.
Hi,
In the following sample application should the ref bool parameter be identified as being unused? I don't think that it should but JustCode does report is as such.
Thanks,
David
using System;
using System.Text;
using System.Data;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
bool bUpdatedLineItem = false;
StringBuilder sb = new StringBuilder();
DataTable dt = new DataTable();
dt.Columns.Add("Price", typeof(double));
for(int i = 0; i < 10; i++)
{
dt.Rows.Add((i + 1) * 1.5);
}
DataRow[] rows = dt.Select();
foreach(DataRow thisRow in rows)
{
CompareDoubleValues(rows, thisRow, sb, "Price", ref bUpdatedLineItem);
}
Debug.Print("Line item updated = {0}", bUpdatedLineItem);
}
private static void CompareDoubleValues(DataRow[] drAry, DataRow dw, StringBuilder sb, string columnName, ref bool bUpdatedLineItem)
{
if(Convert.ToDouble(drAry[0][columnName]) != Convert.ToDouble(dw[columnName]))
{
drAry[0][columnName] = dw[columnName];
bUpdatedLineItem = true;
if(sb != null)
{
sb.Append(columnName).Append(" = ").Append(dw[columnName].ToString()).Append(",");
}
}
}
}
}
In the following sample application should the ref bool parameter be identified as being unused? I don't think that it should but JustCode does report is as such.
Thanks,
David
using System;
using System.Text;
using System.Data;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
bool bUpdatedLineItem = false;
StringBuilder sb = new StringBuilder();
DataTable dt = new DataTable();
dt.Columns.Add("Price", typeof(double));
for(int i = 0; i < 10; i++)
{
dt.Rows.Add((i + 1) * 1.5);
}
DataRow[] rows = dt.Select();
foreach(DataRow thisRow in rows)
{
CompareDoubleValues(rows, thisRow, sb, "Price", ref bUpdatedLineItem);
}
Debug.Print("Line item updated = {0}", bUpdatedLineItem);
}
private static void CompareDoubleValues(DataRow[] drAry, DataRow dw, StringBuilder sb, string columnName, ref bool bUpdatedLineItem)
{
if(Convert.ToDouble(drAry[0][columnName]) != Convert.ToDouble(dw[columnName]))
{
drAry[0][columnName] = dw[columnName];
bUpdatedLineItem = true;
if(sb != null)
{
sb.Append(columnName).Append(" = ").Append(dw[columnName].ToString()).Append(",");
}
}
}
}
}