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();

	lstNew.Add(objList);
}

//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);

Advertisement

JSON Parse Date Format

Code to extract Date or Year from JSON Format Date value


<script>

function GetDate()
{
	var dateString = "\/Date(1453032289681)\/".substr(6);
	var currentTime = new Date(parseInt(dateString ));
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var date = day + "/" + month + "/" + year;
	
	alert(date);
	
	return false;
}

</script>

<input type='button' Value='Get Date' onclick="return GetDate()"/>