Monday, October 10, 2016

C# What is the difference between IEnumerable and IQueryable?

What is the difference between IEnumerable and IQueryable?


IEnumerable and IQueryable may seem like the same at a quick glance, but there are important differences that us, as developers must be aware so that we not only get a working product out the door but also something that performs well.



                      IEnumerable
                    IQueryable
·         IEnumerable exists in the System. Collections namespace.
·         IQueryable exists in the System.Linq Namespace.
·         IEnumerable is suitable for querying data from in-memory collections like List, Array and so on.
·          Example:  IEnumerable<Emp> emp = ent.Emps;
IEnumerable<Emp> temp = emp.Where(x => x.Empid ==5).ToList<Emp>();
This where filter is executed on the client side where the “IEnumerable” code is. In other words, all the data is fetched from the database and then at the client it scans and gets the record with “EmpId” is “5”.
·         IQueryable is suitable for querying data from out-memory like remote database collections.
·         Example : In this case, the filter is applied on the database using the “SQL” query. So the client sends a request and on the server side, a select query is fired on the database and only necessary data is returned.
·         IEnumerable not supported Lazy Loading . Hence not suitable for paging like scenarios.
·         IQueryable supported Lazy Loading .
·         While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filters the data.
·         While querying data from a database, IQueryable executes a "select query" on server-side with all filters.
·         IEnumerable is beneficial for LINQ to Object and LINQ to XML queries.
·         IQueryable is beneficial for LINQ to SQL queries.
·         IQueryable

Using Generics With C#

Using Generics With C#
Generics are most frequently used with collections and the methods that operate on them. Version 2.0 of the .NET Framework class library provides a new namespace, System.Collections.Generic, which contains several new generic-based collection classes.
Generics are different from generic collections. Generic collections are emerged from generic concept. It helps us to maximize code reuse, performance and type safety.
Generics are strongly type collections.
Generics help to decouple the data-type from the logical code snippet which makes the code to reuse again and again.
We can also create classes and pass to it the generic parameter as type.
We can use generics in our code by calling the namespace "using System.Collections.Generic;".
Microsoft applied generic concept on
.NET collections to make generic collections.
Arraylist to make list generic collections.
Hashtables to make Dictionary.
Stacks and Queues to make Stacks and Queues generics.

Example:   public class GenericsClass<T>
    {
   public bool Compare( T a , T b)
        {
            if(a.Equals( b))
            {
                return true;
            }
            return false;
        }    }
     }
    class Program
    {
    public static void Main()
    {
            GenericsClass<int> obj = new GenericsClass<int>();
            bool checkintData =  obj.Compare(10, 10);
            Console.WriteLine("Int data Check:{0}", checkintData);

            GenericsClass<string> obj1 = new GenericsClass<string>();
            bool StringData = obj1.Compare("indian", "indian");
            Console.WriteLine("String data Check:{0}", StringData);    }
    }
OutPut :  True, True
Advantages of Generic:

Type safety - this ensures that the method, class, or interface etc. works only on the correct data type. For example, if you use string when calling a generic method, then all the values passed in as expected to be strings. If you pass in an int value parameter, the compiler will detect that as an error and the program will not be able to compile.
Errors/Exceptions are caught at compile time as opposed to runtime errors/exceptions - if given a choice between compile time and runtime errors, 100% of developers choose compile time errors so should you. The last thing we want is errors crashing the program when the users are working with it.
Re-usability & Flexibility - in the above example on the problem statement, we declared more than one method and the only difference was the data type of the parameters that we passed. With generics, you only have to create one method and re-use it with any data type that you want

Write clean code - we do not need to write methods, class or interfaces that contain complex logic that checks the data type of the parameter values passed in.

Quickly Rename a Mysql database

How do I quickly rename a MySQL database (change schema name)?



From phpMyAdmin, select the database you want to select. In the tabs there's one called Operations, go to the rename section. That's all.
It does, as many suggested, create a new database with the new name, dump all tables of the old database into the new database and drop the old database.


Saturday, October 8, 2016

Using WhatsApp On Web

How do I use WhatsApp Web?


To provide you with a richer communication experience, WhatsApp is now accessible both on your phone and your computer. WhatsApp Web is a computer based extension of the WhatsApp account on your phone. The messages you send and receive are fully synced between your phone and your computer, and you can see all messages on both devices. Any action you take on the phone will apply to WhatsApp Web and vice versa. At this time, WhatsApp Web is available only for Android, iPhone 8.1+, Windows Phone 8.0 and 8.1, Nokia S60, Nokia S40 EVO, BlackBerry and BlackBerry 10 smartphones.

WhatsApp Web is not another WhatsApp account. When you use WhatsApp on your computer and your phone, you are simply accessing the same account on these two devices.

Minimum requirements to enjoy WhatsApp Web


  • You need to have an active WhatsApp account on your phone.
  • You need to have a stable internet connection on both your phone and your computer.
  • You need to use the latest version of Chrome, Firefox, Opera, Safari or Edge as your web browser on your computer.


To get started with WhatsApp Web

1. Visit web.whatsapp.com on your computer.
2. Open WhatsApp on your phone.
  • On Android: in the Chats screen > Menu > WhatsApp Web.
  • On Nokia S60 and Windows Phone: go to Menu > WhatsApp Web.
  • On iPhone: go to Settings > WhatsApp Web.
  • On BlackBerry: go to Chats > Menu > WhatsApp Web.
  • On BlackBerry 10: Swipe down from top of the screen > WhatsApp Web.
  • On Nokia S40: Swipe up from bottom of screen > WhatsApp Web.
  • Scan the QR Code on your computer screen from your phone.
3. Scan the QR Code on your computer screen from your phone.

From your phone, navigate to WhatsApp Web to view your logged in computers or to logout from an active WhatsApp Web session.

Note: To avoid data usage charges on your phone, we recommend that you are always connected to Wi-Fi when using WhatsApp Web.

Friday, October 7, 2016

How to optimize shopping ads: Google Best Practices

A Guide to Shopping Campaign Best Practices

Shopping campaigns give you the chance to feature product images and information directly in your ads. This guide covers how to create high-quality data feeds, structure effective campaigns, set your best bids and simplify the mobile shopping experience.

1. Create high-quality product feeds and keep them fresh

Use relevant titles, descriptions and images to increase CTR but don’t keyword stuff. Read more

Why: When key information comes first in well-designed titles, descriptions and images, your CTR is likely to go up. Forced repetition can also harm your placement.

Keep your feed accurate and up-to-date. Read more

Why: Inaccurate or incomplete feeds will be disapproved by Google because they create a bad experience for users. That means your ads won’t show.

2. Structure your shopping campaigns as you would a storefront

Focus on product lines, profit margins and best sellers. Read more

Why: It will help you budget and bid effectively for your top products.

Promote seasonal items with a separate campaign. Read more

Why: You’re likely to sell more with targeted budgets and marketing messages.

Use multiple campaigns and campaign priorities to promote your flash sales. Read more

Why: You can support and prioritize time-sensitive sales campaigns without restructuring your entire core campaign.

3. Bid based on your goals and your competition

Use benchmark and impression share data to set your best bids. Read more

Why: Some impressions are more valuable than others, so make sure your bids match the value of each.

Bid and budget more when you anticipate peak seasons or shifts in demand. Read more

Why: This will keep your bids competitive at periods of high traffic and opportunity.

4. Make it easy for mobile shoppers

Simplify shopping and checkout. Read more

Why: Mobile users have smaller screens and shorter usage periods.

Don’t forget about mobile tracking. Read more

Why: Shoppers use many devices each day, and mobile can play a big role in conversions.

Bid higher for shopping queries close to your store. Read more

Why: People who do shopping searches near your store are more likely to convert there.

Thursday, October 6, 2016

lambda expression in C#

A lambda expression is an anonymous function means no name of method. The => token is called the lambda operator. It is used in lambda expressions to separate the input variables on the left side from the lambda body on the right side.


Example
delegate int del(int i);
static void Main(string[] args)
{
    del myDelegate = x => x * x;
    int my = myDelegate(5); //my = 25
}


Example 2:

        public static void Main()
        {
            Func<int, int> t = x => x + 1;

            Func<int, int> t2 = x => { return x + 1; };

            Func<string, string> t3 = x => { return x; };

            Action<int> example1 =  (int x) => Console.WriteLine("{0}", x);
       
       
            Console.WriteLine(t.Invoke(1));
            example1.Invoke(7);
            Console.ReadLine();
        }
Output : 2
               7

Using hashtags on Instagram

How do I use hashtags?

You can add hashtags in the caption or comments of your post. If you add hashtags to a post that's set to public, the post will be visible on the corresponding hashtag page.


To tag a photo or video with a hashtag:

1. Take or upload a photo or video
2. Choose to add a filter, then type # followed by text or emoji in the Caption field (ex: #flower)
3. If you want to add a hashtag to a post you've already uploaded, edit the caption or include your hashtag in a comment on your photo

After you tag your post with a hashtag, you'll be able to tap the hashtag to see a page that shows all photos and videos people have uploaded with that hashtag.

Things to keep in mind:

  • When people with private profiles tag posts, they won't appear publicly on hashtag pages.
  • Numbers are allowed in hashtags. However, spaces and special characters, like $ or %, won't work.
  • You can only tag your own posts. You can't tag other people's photos/videos.
  • You can use up to 30 tags on a post. If you include more than 30 tags on a single photo/video, your comment won't post.
  • Older versions of Apple IOS don't support tapping hashtags. Instead, search hashtags by going to  Search & Explore > Search > Tags.