Use the below simple code.
public void CreateFolder(string url, string foldername,string documentlibname)
{
try
{
ClientContext clientContext = new ClientContext(url);
Web web = clientContext.Web;
var query = clientContext.LoadQuery(web.Lists.Where(p => p.Title == documentlibname));## Heading ##
clientContext.ExecuteQuery();
List list = query.FirstOrDefault();
var folder = list.RootFolder;
clientContext.Load(folder);
clientContext.ExecuteQuery();
string[] PathElements = foldername.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < PathElements.Length; i++)
{
folder = folder.Folders.Add(PathElements[i].ToString());
clientContext.ExecuteQuery();
}
//folder = folder.Folders.Add(foldername);
//clientContext.ExecuteQuery();
}
catch (System.Exception ex)
{
throw;
}
}