Monday 28 January 2013

storing values in cache memory(Not sessions not applications)


public static class CacheUtils
    {
        private static readonly Cache cache = HttpRuntime.Cache;
        
        /// <summary>
        /// Gets data from cache      
        public static Object GetFromCache(string key)
        {
            return cache[key];
        }      
 
        public static void InsertIntoCache(string key, int cacheTimeInMinutes, Object obj)
        {
            cache.Insert(key, obj, nullDateTime.Now.AddMinutes(cacheTimeInMinutes),
                          Cache.NoSlidingExpiration, CacheItemPriority.Normal, OnRemove);
        }
 
        public static void OnRemove(string key, object cacheItem, CacheItemRemovedReason reason)
        {
            //log.Info("Object removed from cache: Key-" + key + ": Reason-" + reason);
        }
 
        public static void RemoveFromCache(string key)
        {
            cache.Remove(key);
        }
 
    }

Sunday 27 January 2013

Reverse a string and sentence Linq Query


A string Reverse
string yString = "String to reverse";                
string rString = yString.Reverse().ToString(); 
Sentence reverse with each word in it...
string rString = string.Join(" ",from s in yString.Split(' ')
                                  select new String(s.Reverse().ToArray()));

Monday 14 January 2013

Reg Expressions validator imp list


 Email : "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"



Only Numbers With Decimal :  "^[0-9]*\.?[0-9]+$"

Alphanumeric only :   "^[a-zA-Z0-9]*$"

Numbers with length between 2 to 5 Ex : "^([0-9]{2,5})$"

Numbers with Exact lenght(Example 5) : "^(\d{5})$"