0

I am a php programmer. Unlucky that I have to face some Aspx problem.

I have two dataSource list Objects:

List < Event > eventSource=eventSource.ToList();
List < News > newsSource=newData.ToList();

Although event and News had the same fields(id, title, description, last_updated), they are stored in the different tables (news and event), and there is no relationship between two tables. Both of them had last_updated field which contain a datetime. I need to join them into one table and sort them by last_updated desc.

Then I write something funny with my java(?) knowledge:

List < Object > resultSource=new List < Object >();
foreach (Event eventInfo in eventSource){
   resultSource.Add(eventInfo);
}

I have loop the newsSource and add them in the resultSource. Then I try to use this to sort by datetime:

resultSource=resultSource.OrderBy(???).ToList();

But I don't know what parameter should be filled in that ??? area, and I found that I cannot get the "resultInfo.title" in the foreach loop, because I don't have "title" field in the Object class.

Do I have anyway to solve this in simple way?


No need for regex; built in URL functions should work more reliably.

// Parse the url first
$url = parse_url($string);

// Parse your query string into an array
parse_str($url['query'], $qs);

// Replace the var3 key with your variable
$qs['var3'] = $myVariable;

// Convert the array back into a query string
$url['query'] = http_build_query($qs);

// Convert the $url array back into a URL
$newstring = http_build_url($url);

Check out http_build_query and parse_str. This will append a var3 variable even if there isn't one, it will URL encode $myVariable, and its more readable than using preg_replace.

4

1 回答 1

1

您需要使用 lambda 表达式。就像是:

resultSource=resultSource.OrderBy(res => res.Name).ToList();

但是用Name您想要排序的任何属性替换。

于 2013-02-25T02:47:42.977 回答