Posts

Showing posts from April, 2016

LINQ Queries with GROUP BY, INNER JOIN, COUNT and SUM: Examples

Examples of different LINQ queries in C#: GROUP BY, INNER JOIN, COUNT and SUM Setup the LINQPad against the Northwind database. 1. LINQ query with GROUP BY, JOIN and SUM.     Find the quantities required for each product to fulfill all the orders.     Here the tables we have to use are Products and Order Details. Both of these tables can be joined on    ProductID key and grouped by Product Name to make sure that the Quantity is calculated against a named product instead of ID.     The SQL query for the above requirement is :        s elect A.ProductName,sum(B.Quantity)         from Products P join "Order Details" OD         on A.ProductID=B.ProductID         group by A.ProductName     The equivalent LINQ query for the above is:                 from p in Products         join od in OrderDetails         on p.ProductID equals od.ProductID         group od by p.ProductName into g         select new { ProductName=g.Key, Quanti=g.Sum(a => a.Quantity)}      2. LIN

How to run Facebook and other restricted sites from company network

How to run Facebook and other restricted sites from company network  In some companies, the browsing is restricted in two ways. One is through proxy restriction and other one is through network traffic restriction.  In cases of proxy restriction, we can use chain of free proxies to access or we can use google translate.  In cases of traffic restriction, we can use a firefox extension called Browsec. If you dont have admin rights to install firefox, download a portable version of Firefox browser and install this extension.  Once installed, turn it on and do happy browsing.  Ple ase add you r comments if it helps....

How to run WhatsApp in a PC

How to run WhatsApp in a PC without mobile internet turned on in mobile: Usually, if we want to run whatsapp from PC, we have go to whatsappweb, scan the QR and register that PC to mobile. But this whatsappweb synchronizes the data from phone and shows it on web. In such cases, your mobile should also be connected to the internet to see updated messages in whatsappweb.  This just defeats the purpose sometimes. To go without the mobile is not connected internet, we can use BlueStacks application. This application emulates the android environment and works as an android device. Once it is installed it will take a tablet UI. Rest, we can register that device with the google account and start installing WhatsApp and using it as in a smart phone. Here during WhatsApp registration we need to give OTP. Thats all..  

Algorithm to remove duplicate characters from a string: C#

Algorithm to remove duplicate characters from a string: C# class Program     {         static void Main(string[] args)         {             Console.WriteLine("Enter the String");             string inp = Console.ReadLine();                        string du = RemoveDuplicates(inp);             Console.WriteLine(du);             Console.ReadKey();         }         static string RemoveDuplicates(string input)         {             StringBuilder result=new StringBuilder();             char[] chars = input.ToCharArray();                         for(int i=0;i<chars.Length;i++)             {                 int counter = 0;                 for (int j=i+1; j<chars.Length;j++)                 {                                         if (chars[i] == chars[j])                         counter++;                 }                 if(counter<1)                 result.Append(chars[i]);             }             return result.ToString();         }     } Ple ase add you r com

Algorithm to find a string contains unique characters or not: C#

Algorithm to find a string contains unique characters or not: class Program     {         static void Main(string[] args)         {             Console.WriteLine("Enter the String");             string inp = Console.ReadLine();             bool result = CheckUniq(inp);             if (!result)                 Console.WriteLine("The input string contains duplicate characters");             else Console.WriteLine("No duplicates");         }         static bool CheckUniq(string input)         {             //take a bool array of size 256 considering the ASCII             bool[] char_set = new bool[256];             for(int i=0;i<input.Length;i++)             {                 int val = input[i];                 if (char_set[val]) return false;                 char_set[val] = true;             }             return true;         }     } We can also sort the string and check whether the adjacent characters are equal or not. But as usual, sorting algorit