C# Sort List with Custom Data Type

C# Sort List with Custom Data Type

Sample Class:

				class ListClassName
					public string ID { get; set; }
					public string Title { get; set; }					
					public string Year { get; set; }					

From Above class we create List and needs to sort by Year Column

//Create List From Class 
List<ListClassName> lstNew = new List<ListClassName>();

//Add Records to List
foreach (var item in lstData)
	ListClassName objList = new ListClassName();

	objList.ID = item.PublicationId.ToString();
	objList.Title = item.Title.ToString();
	objList.Year = item.Releaseobj1.ToString();


//Sort By List Column Name
lstNew.Sort(delegate(ListClassName obj1, ListClassName obj2)
	return obj2.Year.CompareTo(obj1.Year);

//Assign Value to cntrol or use in another way
txtTemp.Value = serializer.Serialize(lstNew);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s