Is this acceptable practice
-
There is a method of the DataTable object that I require to access from various methods of my class basically to retrieve the column name as a specific index. I have created a private property in my class to access this method and defined it similar to as follows:
private string ColumnName { get {return DataTable.Columns[ColumnNumber].ColumnName.ToString();} set {DataTable.Columns[ColumnNumber].ColumnName = value;} }
Is this acceptable practice? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net -
There is a method of the DataTable object that I require to access from various methods of my class basically to retrieve the column name as a specific index. I have created a private property in my class to access this method and defined it similar to as follows:
private string ColumnName { get {return DataTable.Columns[ColumnNumber].ColumnName.ToString();} set {DataTable.Columns[ColumnNumber].ColumnName = value;} }
Is this acceptable practice? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.NetThis is certainly "acceptable", however, you might ask yourself "what is the benefit?". Considering that your DataTable and ColumnNumber fields appear to be instance variables, there's no reason when you need that specific column name you can't just call it directly as in DataTable.Columns[ColumnNumber].ColumnName. If what you want is a short cut method, create some methods like this (that aren't properties).
private string GetColumnNameAt( int index )
{
if( DataTable.Columns[index] != null )
return DataTable.Columns[index].ColumnName;
}private void SetColumnNameAt( int index, string name )
{
if( DataTable.Columns[index] != null )
DataTable.Columns[index].ColumnName = name;
}Let me know if you need clarification. Best Regards. -Matt ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall