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?


Cid and Sid is Nullable, so you can use HasValue property to check if the variable has value or not (null)

  public ViewResult Index(int? CId,int?SId,string name,int? p)
  {
        if (!CId.HasValue || !SId.HasValue)
        {
            CId = 1;
            SId = 1;
        }
  }
4

1 に答える 1

1

ラムダ式を使用する必要があります。何かのようなもの:

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

ただし、Name並べ替えたいプロパティに置き換えます。

于 2013-02-25T02:47:42.977 に答える