Programmatically Check whether Current Logged in User is a Member of SharePoint User Group or Not

SharePoint Custom development requires to check whether the current logged in user is a member of any particular SharePoint User Group or not. We can solve this issue by using the code block given below.

bool isMember = false;  

SPSecurity.RunWithElevatedPrivileges(delegate  
{  
     using (SPSite site = new SPSite("http://siteurl"))  
     {  

         SPWeb web = site.RootWeb;  
         string groupName = "Site Group Name";  

         var spGroup = web.Groups[groupName];  
         isMember = web.IsCurrentUserMemberOfGroup(spGroup.ID);  
     }  
});