I want to identity a subset of a collection, tradeProperyRows (defined
as DataRow[]). Then I want to switch the data (in two columns of
DataRow) in the subset (trsTrades).
However, I want to make sure that trsTrades is a collection of
pointers to the original array(tradeProperyRows), instead of a copy of
the items of the subset, because I want to alter the items in the
**original** array, tradeProperyRows.
Please let me know if the code below would do the job. Thanks!
// Use LINQ to get the subset that meets the criteria
IEnumerable<DataRow> selected = from n in tradeProperyRows
where
Regex.IsMatch(n["TRADETYPE"].ToString(), ".*TRS$")
select n;
// Get the subset to a List
List<DataRow> trsTrades = selected.ToList();
// Switch data in QUANTITY and PRINCIPAL columns in the subset
// Switch the data in the **original** array, tradeProperyRows!!!
foreach (DataRow dr in trsTrades)
{
if (dr.Table.Columns.Contains("PAY_TR_LEG"))
{
// Switch data in QUANTITY and PRINCIPAL columns
double tempFigure =
Convert.ToDouble(ClrDbTypeConverter.GetClrValue(dr["QUANTITY"]));
dr["QUANTITY"] =
Convert.ToDouble(ClrDbTypeConverter.GetClrValue(dr["PRINCIPAL"]));
dr["PRINCIPAL"] = tempFigure;
}
|