Content Type - Setting up default content type programmatically

Here’s the sample to add and set a new content type as a default content type to a document library in a SharePoint site. Also this will hide the pervious default content type.

 SPSite oSPSite = new SPSite(""); // Site URL
 SPWeb oSPWeb = oSPSite.OpenWeb();
 SPList list = oSPWeb.Lists["Shared Documents"];  // Name of the List
 SPContentType newContentType2 = oSPWeb.ContentTypes["ContentType_Two"]; // ContentType Two’s name
 list.ContentTypes.Add(newContentType2);
 SPContentTypeCollection currentOrder = list.ContentTypes;
 List<SPContentType> result = new List<SPContentType>();
 foreach (SPContentType ct in currentOrder)
 {
     if (ct.Name.Contains("ContentType_Two"))
     {
         result.Add(ct);
     }
 }
 list.RootFolder.UniqueContentTypeOrder = result;
 list.RootFolder.Update();