I was shocked to learn that the process of applying arithmetic order of operations was already available to you in .Net. Sure it can be done through a slightly obscure fashion, but the results are fantastic. Better yet nearly only 4 lines of code...amazing.
string expression = "(2.2 + .8) * 10";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("col1", typeof(double), expression);
dataTable.Rows.Add(new object[] { });
MessageBox.Show(Convert.ToString(dataTable.Rows[0][0]));
Outputs 30....What a time saver.
Friday, April 24, 2009
Wednesday, February 25, 2009
Converting List types in C#
I was searching earlier and saw that many people's solution to this issue is implementing a for loop. No need with >= c#2.0 List has a very handy ConvertAll method.
I have a quick example of the awesome power in 2 lines of code.Convert List<int> into a List<string> or List<int> into an array of strings which I needed to join a list of ids.
List<int> myList = new List<int>(){ 101,202,332,343};
string sIdList = string.Join(",", myList.ConvertAll<string>(delegate(int i){return i.ToString();}).ToArray());
sIdList output is "101,202,332,343"
I hope this helps someone else.
I have a quick example of the awesome power in 2 lines of code.Convert List<int> into a List<string> or List<int> into an array of strings which I needed to join a list of ids.
List<int> myList = new List<int>(){ 101,202,332,343};
string sIdList = string.Join(",", myList.ConvertAll<string>(delegate(int i){return i.ToString();}).ToArray());
sIdList output is "101,202,332,343"
I hope this helps someone else.
Monday, February 2, 2009
SQL Server 2008 Edit Top 200 Rows
I thought this feature was fixed, but glad to see that you can override very easily in the SQL Object Browser interface. Tools - Options - Sql Server Object Explorer
Labels:
Edit All,
Edit Top 200 Rows,
Select All,
SQL Server 2008
C# DataTable with Custom Objects
Came across this little tidbit to allowing custom object types in a .net DataTable. Issue being that if you don't set the property, you get the string value of the object.
DataTable dt = new DataTable();
DataColumn dcMyObject = new DataColumn("MyObject");
dcMyObject.DataType = typeof("MyNameSpace.MyClass");
dt.Columns.Add(dcMyObject);
DataColumn dcMyObject = new DataColumn("MyObject");
dcMyObject.DataType = typeof("MyNameSpace.MyClass");
dt.Columns.Add(dcMyObject);
Thursday, January 29, 2009
Subscribe to:
Comments (Atom)