Interview Questions


Sunday, July 15, 2018

DDL: dynamic link library
Cache is stored in RAM
IL: Intermediate Language
Delegate: delegate is a pointer to a function


public int Ramiz_SavePack(IPacking pack)
    {
        using (var conn = (SqlConnection)connector.GetConnection())
        {
            conn.Open();
            SqlTransaction transaction;
            var comm = (SqlCommand)connector.GetCommand("Ramiz_Pack_Save");
            comm.CommandType = CommandType.StoredProcedure;
            transaction = conn.BeginTransaction();
            comm.Transaction = transaction;
            int rowNum = 0;

            try
            {
                if (!string.IsNullOrEmpty(pack.BrojKolete))
                    comm.Parameters.Add("@BrojKolete", SqlDbType.NVarChar).Value = pack.BrojKolete;
                else
                    comm.Parameters.Add("@BrojKolete", SqlDbType.NVarChar).Value = DBNull.Value;
                comm.Parameters.Add("@Bosanski", SqlDbType.NVarChar).Value = pack.Bosanski;
                comm.Parameters.Add("@Kom", SqlDbType.Float).Value = pack.Kom;
                comm.Parameters.Add("@Vrsta", SqlDbType.NVarChar).Value = pack.Vrsta;
                comm.Parameters.Add("@Datum", SqlDbType.Date).Value = pack.Datum;
                comm.Parameters.Add("@BrojKamiona", SqlDbType.Int).Value = pack.BrojKamiona;

                 rowNum = comm.ExecuteNonQuery();
                transaction.Commit();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                try
                {
                    conn.Close();
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.Message);
                }
            }
            return rowNum;
        }
    }

Virtual Keyword: Virtual is here give permission to its child class to go ahead and overwrite.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            test objclass = new overtest();
            objclass.show();
        }
    }
    class test
    {
        public virtual void show()
        {
            Console.WriteLine("base class");
        }
    }
    class overtest :test
    {
        public override void show()
        {
            Console.WriteLine("child class");
        }
    }
}

Output : child class






What is the use of shadowing in c#?
https://www.youtube.com/watch?v=xmjOPCnSE30
Shadowing means basically parents elements (i) is completely replaced by child elements in terms of data (variable, method or functions)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            class1 obj1 = new class1();
            class2 obj2 = new class2();
            obj1.i = 123;
            obj2.i();
        }
    }
    public class class1
    {
        public int i;
    }
    public class class2: class1
    {
        public void i()
        {

        }
    }
}
Static keyword
Static Classes and class members are used to create data and methods that can be accessed without creating an instance of the Class. The keyword Static can be applied to the Classes, field, method, properties, operator, event and constructors.
Class products
{
Public static int price;
                Public static void showinfo();
}
We can call variables and methods of static classes without creating an instance of the class. That means you cannot use the new keyword to create a variable of the class type. We can call static members and methods directly from classes like the following:
Product.price = 100;
Product.showInfo();


What is delegates??
https://www.youtube.com/watch?v=ifbYA8hyvjc&t=340s
Delegates is a pointer to a function.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            class2 objcls = new class2();
            objcls.numberlist(callback);
        }
        static void callback(int i)
        {
            Console.WriteLine(i);
        }
    }
    public class class2
    {
        public delegate void callback(int i);
        public void numberlist(callback obj)  // Function
        {
            for (int i = 0; i < 1000; i++)
            {
                obj(i);
            }
        }
    }

}

What is an Abstract Class?

An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.
GC - Garbage Collector – Feature provided by CLR to clean up unused managed objects
Managed and Unmanaged Code –
Anything which is within boundary of CLR is called managed code, Outside boundary of CLR is called Unmanaged code

C# Out parameters Vs REF parameters

Out and Ref are c# keywords which helps you to pass variables data to function and methods by reference.
Ref parameter:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            int val = 10;
            calculate(ref val);
            Console.WriteLine(val);
        }
        static void calculate(ref int val)
        {
            val = val + 1;
        }
    }
}
Output: 11
Out Parameter:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            int val = 10;
            calculate(out val);
            Console.WriteLine(val);
        }
        static void calculate(out int val)
        {
            val = 0;
            val = val + 1;
        }
    }
}
Output: 1

Reflection in .Net –
https://www.youtube.com/watch?v=y8-uq6Ur7Dc
Reflection is inspecting assembly metadata (.ddl) to find out how many class this assembly have or how many method that particular class have.
Early binding:  Create Instance of class at compile time is called Early binding

Late Binding : Create Instance of class at run time is called late binding.
.Net Basic
Basic of .net
-          IL Code, CLR, CTS, code access security, Garbage collector, global assembly cache, value type, reference type, boxing unboxing
Oops
-          Abstraction, encapsulation, polymorphism, inheritance, what is difference between abstract class and interface. What is shadowing.
SQL Server
-          Indexes, cluster indexes, non-cluster indexes, normalization, denormalization
ADO.Net
-          Difference between Dataset, data reader, different component in ADO.net like dataset, data reader, data adaptor, data view, connection objects
Asp.net
-          ASP.net Page life cycle, post back, http handler, http module, sessions variables, view state, how to do authentication, authorization
Web services
-          SOAP, REST, WSDL, what is asmx file and what is the use of web services, OData
New Technologies
WCF
-          What is operation contract, what is services contract, what is end point, what is address, binding, contracts, what is the difference between web services and wcf services.
WPF / Silverlight
-          What is XML file, what is different kind of components which are available in Silverlight. How is the silver light framework, why MVVM is good in WPF and Silverlight
LINQ / Entity framework – OR Maper
-          Why do we need LINQ, why do we need entity framework, what is data contacts, what is object contact, how do you use stored procedure in entity framework and LINQ. In what scenario LINQ is good, what scenario entity framework is good.
Azure / cloud computing
-          Tables, queues, BLOB and all different azure components which help you to do cloud computing.
WWF – work flow
-          Sequencing workflow, state machine workflow
Architecture
Design Patterns
-          Factory patterns, abstract factory patterns, singleton and in what scenarios what are good.
MVC / MVP / MVVM
-          What is MVC(Model view controller), what is MVP(model view presenter), what is MVVM(model view viewmodel) and in what scenario MVC is better than MVP and when we should use MVVM,
UML Notations
-          How to write a use case, what is class diagram, sequence diagram
Documentation
-          Different type of document available in projects, technical document, how to write it, different section in technical document.
Requirement to design
-          how does requirement document look like, how does technical document look like.


Process
Agile
-          explain agile, how agile process looks like,
-          explain scrum
-          waterfall
-          SDLC process
Estimation Methodology
-          Function point analysis
-          Work breakdown structure
CMMI
SIX Sigma




What are generics and what are generic collections?
How many types of collections are there in .net?
Array, Array List, hash table and specialize collections.
Array:
Strong point
Array are strong type so there is no boxing and unboxing, so the performance is much better.
Week point
Fixed length
Array list & Hash table
Strong point:
Resizable
Week point
They take only object, so there is lots of boxing and unboxing
We needed something strong type as well as resizable, that’s the reason we use generics.
In general : Generics collections helps us to create flexible strong type collection, In Other word, Remove Datatype from Logic is called Generic.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
            bool check;
            calcul<Int32> objcla = new calcul<Int32>();
            check = objcla.calculate(1, 2);
            Console.WriteLine(check);

            calcul<String> objcla1 = new calcul<String>();
            check = objcla1.calculate("Raj","Raj");
            Console.WriteLine(check);
        }
       
    }
    class calcul<CHECKTYPE>
    {
        public bool calculate(CHECKTYPE x, CHECKTYPE y)
        {
            if (x.Equals(y))
            {
  return true;
     }
            else
            {
                return false;
            }
        }
    }
}
Difference Between “==” and “. Equals ()”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interview
{
    class Program
    {
        static void Main(string[] args)
        {
       //object o = ".Net Interview Questions"; //Instance o
//object o1 = o; // Reference of o is passed to o1, so reference is same //for o and o1, also content are same.


            object o = ".Net Interview Questions"; // Instance o
            object o1 = new string(".Net Interview Questions".ToCharArray());
            // new reference is created for o1

            Console.WriteLine(o == o1); // Comparing Reference Type
            Console.WriteLine(o.Equals(o1)); // Comparing Content
        }
       
    }
}

Output:
False
True
Note: if your datatype is string, it always does content comparison.

What is GAC?
GAC: Global Assembly cache
GAC have strong named assembly, assemblies in the GAC can be shared by all applications running on the machine without having copy in local projects.
Example :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

here System, is assembly in GAC, you don’t need to add every time to project, they come by default.