Posts

Showing posts from January, 2018

How to split the String values with a word in C#

string str="srinivas<br / >nivas <br / >Sri" Result : List<string> strNames = str.Split(new[] { "<br />" },StringSplitOptions.None).ToList(); Distincr names: List<string> strNames = str.Split(new[] { "<br />" },StringSplitOptions.None).Distinct().ToList();

How to add to List of Strings in one dictonary like dictonary in c#

First u can take 2 list of Strings Var a =new List<string>(){"API","UI"} ; var b=new List<string> (){"Application Programming Interface","User Interface"} ; Result: ===== API = Application Programming Interface UI = User Interface Firs you can create on extension method for this       public static class ExtentionMethod { public static void YDR<T>(this IEnumerable dr,Action<T,int> y) { int initials = 0; foreach (T item in dr) { y(item,initials ++); } } }          public static Dictionary<TKey,TValue> Adding<TKey, TValue>(IEnumerable<TKey> keys,IEnumerable<TValue> values) { var dictonary = new Dictionary<TKey,TValue>(); keys.YDR<TKey>((x,i) => { dictonary .Add(x,values.ElementAt(i)); }); return dictonary; } Use case : ======= Create a class and use this method public Dictionary<...

Convert Time to decimal in C#

Can we take the time value is roughly at 10:30:00 Type1   decimal output= Convert . ToDecimal ( TimeSpan . Parse ( "10:30" ). TotalHours ); Net Approch will be 2 nd Type is var startTime= TimeSpan . Parse ( "10:30" ) ; var endTime=TimeSpan . Parse ( "11:30" ); var result = endTime - startTime; decimal output= result.Hours+result.Minites/60; Here minites should be reater than 0.