Monday, 30 April 2018

IQ


  • Why can't static classes have non-static methods and variables?
  1.  Static classes can't be instantiated in the first place, so even if you could declare non-static (instance) members, they can never be accessed. Since there really isn't a point allowing it for that reason, the language simply prohibits it.
  2. A non-static class can have both static and non-static members so that the static members apply to the class, 
  • whereas the non-static members apply to the instances of that class.
  • Difference between a property and variable
  • The following table shows some important differences between variables and properties.
    Point of differenceVariableProperty
    DeclarationSingle declaration statementSeries of statements in a code block
    ImplementationSingle storage locationExecutable code (property procedures)
    StorageDirectly associated with variable's valueTypically has internal storage not available outside the property's containing class or module

    Property's value might or might not exist as a stored element 1
    Executable codeNoneMust have at least one procedure
    Read and write accessRead/write or read-onlyRead/write, read-only, or write-only
    Custom actions (in addition to accepting or returning value)Not possibleCan be performed as part of setting or retrieving property value
  • difference between a DataTable and a DataReader
  • DataReader
    1. Its an connection oriented, whenever you want fetch the data from database that you need the connection. after fetch the data connection is diconnected. 
    2. Its an Read only format, you cann't update records. 


    DataSet
    1. Its connectionless. whenever you want fetch data from database. its connects indirectly to the database and create a virtual database in local system. then disconnected from database.
    2. Its easily read and write data from virtual database.

    DataTable
    A DataTable object represents a single table in the database. It has a name rows and columns.
    There is not much difference between dataset and datatable, dataset is just the collection of datatables.

  • Difference between var and dynamic
vardynamic
Introduced in C# 3.0
Introduced in C# 4.0
Statically typed – This means the type of variable declared is decided by the compiler at compile time.
Dynamically typed - This means the type of variable declared is decided by the compiler at runtime time.
Need to initialize at the time of declaration.
e.g., var str=”I am a string”;
Looking at the value assigned to the variable str, the compiler will treat the variable str as string.
No need to initialize at the time of declaration.
e.g., dynamic str; 
str=”I am a string”; //Works fine and compiles
str=2; //Works fine and compiles
Errors are caught at compile time.
Since the compiler knows about the type and the methods and properties of the type at the compile time itself
Errors are caught at runtime 
Since the compiler comes to about the type and the methods and properties of the type at the run time.
  • Difference Between Constant and ReadOnly and Static
Const
Const is nothing but "constant", a variable of which the value is constant but at compile time. And it's mandatory to assign a value to it. By default a const is static and we cannot change the value of a const variable throughout the entire program.

Readonly
Readonly is the keyword whose value we can change during runtime or we can assign it at run time but only through the non-static constructor. Not even a method. Let's see:

Static ReadOnly
A Static Readonly type variable's value can be assigned at runtime or assigned at compile time and changed at runtime. But this variable's value can only be changed in the static constructor. And cannot be changed further. It can change only once at runtime. Let's understand it practically.

Static 

The static keyword is used to declare a static member. If we are declare a class as a static class then in this case all the class members must be static too. The static keyword can be used effectively with classes, fields, operators, events, methods and so on effectively.
  • Default visibility for C# classes and members (fields, methods, etc.)?
  • Default access modifier of class is Internal. And private for class member.

Members of    Default member accessibility
----------    ----------------------------
enum          public
class         private
interface     public
struct        private


  • What is the difference between <%# Bind(“”) %> and <%# Eval(“”) %> in ASP.NET?
EVal is one way binding, Bind is two way
If you bind a value using Eval, it is like a read only. You can only view the data.
If you bind a value using Bind, and if you do some change on the value it will reflect on the database also


  • Jquery Method chaining
To chain an action, you simply append the action to the previous action.
The following example chains together the css(), slideUp(), and slideDown() methods. The "p1" element first changes to red, then it slides up, and then it slides down:

$("#p1").css("color", "red").slideUp(2000).slideDown(2000);






  • Where is viewstate information stored (server or client)? and in which format?

            By default the ViewState will be stored in the html page and will be submitted to the server    when the user submit that page again, then the server will extract the ViewState from the Submitted form, and populate the ViewState bag

C# Program to Calculate the Power Exponent Value

  1. /*
  2.  *  C# Program to Calculate the power exponent value
  3.  */
  4. using System;
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.  
  10.         double m, n;
  11.         Console.WriteLine("Enter the Number : ");
  12.         m = double.Parse(Console.ReadLine());
  13.         Console.WriteLine("Enter the Exponent : ");
  14.         n = double.Parse(Console.ReadLine());
  15.         double value1 = Math.Pow(m, n);
  16.         Console.WriteLine("Result : {0}", value1);
  17.         Console.ReadLine();
  18.     }
  19. }

2nd method

public static void Main()
        {
            double m, n,y=1;
            Console.WriteLine("Enter the Number : ");
            m = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter the Exponent : ");
            n = double.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                y = y * m;

            }

            Console.WriteLine(y);
            Console.ReadLine();
        }
Here is the output of the C# Program:
Enter the Number : 2
Enter the Exponent :3
Result : 8
  • Define Custom Route
  • How to get cell value of gridview using JQUERY

<script type="text/javascript">
        $(document).ready(function() {
            var list = "";
            $("#btnGet").click(function() {
                $("#<%=GridView1.ClientID %> tr").each(function() {
                    //Skip first(header) row
                    if (!this.rowIndex) return;
                    var age = $(this).find("td:last").html();
                    list += age + "</br>";

                });
                $("#listAge").html(list)
            });

        });
    </script>

  • WCF Service Instancing

PerCall: A new service object is created for each call to the service.
 PerSession: A new service object is created for each client. This is the default behavior.
 Single: A single service object is created for all calls from all clients.

[ServiceBehavior(InstanceContextMode= InstanceContextMode.PerCall)]

public class PerCallService :IPerCallService

[ServiceBehavior(InstanceContextMode= InstanceContextMode.PerSession)]

PerSession is the default instancing mode for WCF.


public class PerSessionService:IPerSessionService

[ServiceBehavior(InstanceContextMode= InstanceContextMode.Single)]

public class SingletonService:ISingletonService

Wcf Instance Management Per Call Service
Wcf Instance Management Per Session Service
Wcf Instance Management Singleton Service

No comments:

Post a Comment