Hi folks, I recently moved from vb.net to c#. I normally store my dataview in a session object for sorting and paging purposes. (asp.net apps)
I'm curious to know what is the difference between the following....
Code:Type T = Session["SessionDataViewTable"].GetType(); /*Above, I get the type of the Session variable that contains a dataview */ object[] param = new object[1];// creating an object array with only 1 element in size param[0] = e.SortExpression + " " + Session["SortOrder"]; //Above, I set the element zero to the initial sort order string T.InvokeMember("Sort", BindingFlags.SetProperty, null, Session["SessionDataViewTable"], param); //Above, I Invoke the "sort" member of the dataview object. /* I had to check before what type of member it is, and that is why I specify in the binding flags that it is a SetProperty */
and....
Code:((DataView)Session["SessionDataViewTable"]).Sort = "id" + " " + Session["SortOrder"];
Originally, when I first moved from vb.net to c#(last week), I tried to do this...
I got a compiler error stating something to do with Sort not being a member of that session variable. So I did the research and found out that vb.net allows this late binding that I got used to. I read online that I need to do my own late binding. Then I find out that I could just cast it to get the method.Code:Session["SessionDataViewTable"].Sort = "id" + " " + Session["SortOrder"];
Is there a difference beside the fact that one of my options requires only 1 line of code?
Thx![]()





Reply With Quote