Sunday, October 28, 2012

What is a Delegate?

Delegate is a type which  holds the method(s) reference in an object. It is also referred to as a type safe function pointer.





Declaration


public delegate double Delegate_Prod(int a,int b);
class Class1
{
    static double fn_Prodvalues(int val1,int val2)
    {
        return val1*val2;
    }
    static void Main(string[] args)
    {
        //Creating the Delegate Instance
        Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
        Console.Write("Please Enter Values");
        int v1 = Int32.Parse(Console.ReadLine());
        int v2 = Int32.Parse(Console.ReadLine());
        //use a delegate for processing
        double res = delObj(v1,v2);
        Console.WriteLine ("Result :"+res);
        Console.ReadLine();
    }
}

Explanation

Here I have used a small program which demonstrates the use of delegate.
The delegate "Delegate_Prod" is declared with double return type and accepts only two integer parameters.
Inside the class, the method named fn_Prodvalues is defined with double return type and two integer parameters. (The delegate and method have the same signature and parameter type.)
Inside the Main method, the delegate instance is created and the function name is passed to the delegate instance as follows:
Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
After this, we are accepting the two values from the user and passing those values to the delegate as we do using method:
delObj(v1,v2);
Here delegate object encapsulates the method functionalities and returns the result as we specified in the method.

Friday, July 20, 2012

How To call Mvc Function With Json



    $(document).ready(function () {
        $("#ddlModelSeries").change(function () {

            var Mname = $(this).val();

            $.getJSON("AddModelSeries/LoadBrand", { id: Mname }, function (AreaData) {
                var select = $("#ddlBrand"); select.empty(); select.append($('
                $.each(AreaData, function (index, itemData) {

                    select.append($('
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });

            });

        });


    });

             



how to hide menu in mvc 3 on master page





@if(Session["username"] !=null)
    {
 

 
     
 @Html.ActionLink("Manange Step", "Index", "Adminmanage")
 &nbsp 
@Html.ActionLink("Manange Errorcode", "Index", "Admin")&nbsp&nbsp

 @Html.ActionLink("LogOut", "LogOn", "Account")&nbsp&nbsp
     

        }

how pass value from page to javascript with hidden varible


@model UFixnow.Models.ModelSeries
@{
    ViewBag.Title = "Index";
   Layout = "~/Views/Shared/_Adminlayout.cshtml";
    var id = Session["SeriesId1"];
}





Tuesday, July 10, 2012

oops Concepts



 Abstraction

The process of picking out (abstracting) common features of objects and procedures. A programmer would use abstraction, for example, to note that two functions perform almost the same task and can be combined into a single function. Abstraction is one of the most important techniques in software engineering and is closely related to two other important techniques -- encapsulation and information hiding. All three techniques are used to reduce complexity.



Difference between Struct and Class

Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.
Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.
Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.



Boxing and Un-Boxing

Boxing: means converting value-type to reference-type.

Eg:

int I = 20;

string s = I.ToSting();


UnBoxing: means converting reference-type to value-type.

Eg:

int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.


Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.




http://dng-oops.blogspot.in/









Virtual Method

By declaring base class function as virtual, we allow the function to be overridden in any of derived class.

Eg:

Class parent

{

virtual void hello()

{ Console.WriteLine(“Hello from Parent”); }

}


Class child : parent

{

override void hello()

{ Console.WriteLine(“Hello from Child”); }

}


static void main()

{

parent objParent = new child();

objParent.hello();

}

//Output

Hello from Child.





Access Modifiers

Access Modifiers are keywords used to specify the declared accessibility of a member of a type.

Public is visible to everyone. A public member can be accessed using an instance of a class, by a class's internal code, and by any descendants of a class.


Private is hidden and usable only by the class itself. No code using a class instance can access a private member directly and neither can a descendant class.

Protected members are similar to private ones in that they are accessible only by the containing class. However, protected members also may be used by a descendant class. So members that are likely to be needed by a descendant class should be marked protected.




Encapsulation

Is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.

Real time
e.g. / Ink is the important component in pen but it is hiding by some other material

Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly; rather, they are encapsulated by the class.

For example code

Public class Calculations
{
  private void fnMultiply(int x, int y)
  {
  return x * y;
  }
}
...
...
Calculations obj;
int Result;
Result = obj.fnMultiply(5,10)




ENCAPSULATION MEANS HIDING ALL THE INTERNAL DETAILS OF THE METHODS.

EXAMPLE cars and owners...
all the functions of cars are encapsulated with the owners..
No one else can access it...





Friday, June 8, 2012

how to set dropdownlist max item in asp net


Set these value in dropdown

onmouseover="this.size=4;"
onmouseout="this.size=1;"

Friday, March 23, 2012

what is CLR,JIT,GAC,GC


CLR means Common Language Runtime.It is  Major component of 
the .NET frameworkIt provides no of benefits to the 
developers such as Exception handling,Security,Debugging 
and Versioning.

Common Language Runtime is Runtime engine which converts 
Microsoft Intermediate Language in machine understandable 
code, it is similar to JVM in Java


working of CLR:-

When the .NET program is compiled, the output of the 
compiler is not an executable file but a file that contains 
a special type of code called  the Microsoft Intermediate 
Language (MSIL), which is a low-level set of instructions 
understood by the common language run time. This MSIL 
defines a set of portable instructions that are independent 
of any specific CPU. It's the job of the CLR to translate 
this Intermediate code into a executable code when the 
program is executed making the program to run in any 
environment for which the CLR is implemented. And that's 
how the .NET Framework achieves Portability. This MSIL is 
turned into executable code using a JIT (Just In Time) 
complier. The process goes like this, when .NET programs 
are executed, the CLR activates the JIT complier. The JIT 
complier converts MSIL into native code on a demand basis 
as each part of the program is needed. Thus the program 
executes as a native code even though it is compiled into 
MSIL making the program to run as fast as it would if it is 
compiled to native code but achieves the portability 
benefits of MSIL.

jit:

Before Microsoft intermediate language (MSIL) can be
executed, it must be converted by a .NET Framework
just-in-time (JIT) compiler to native code, which is
CPU-specific code that runs on the same computer
architecture as the JIT compiler. 
Rather than using time and memory to convert all the MSIL in
a portable executable (PE) file to native code, it converts
the MSIL as it is needed during execution and stores the
resulting native code so that it is accessible for
subsequent calls.

JIT compiler is a part of the runtime execution environment.
In Microsoft .NET there are three types of JIT compilers.

Pre-JIT : Pre-JIT compiles complete source code into native
code in a single compilation cycle. This is done at the time
of deployment of the application.

Econo-JIT : Econo-JIT compiles only those methods that are
called at runtime. However, these compiled methods are
removed when they are not required.

Normal-JIT : Normal-JIT compiles only those methods thar are
called at runtime.

What is GAC?
A shared assembly has version constraints. It is stored in the Global Assembly Cache (GAC). GAC is a repository of shared assemblies maintained by the .NET runtime. The shared assemblies may be used by many applications. To make an assembly a shared assembly, it has to be strongly named.
GC:
In .NET Garbage Collector maintained by CLR. The process of 
GC is reclaim the memory of objets which is no longer 
referenced by our program.Next thing is GC runs 
undeterministicly because of that we can't assure we the 
object will be released from the Heap Location

If there is any memory defeciency then only GC will called 
by CLR. GC always runs on the priority basis. If size of free 
memory is more, than GC runs on low priority basis.  And if 
memory becomes low than GC Starts running on high priority 
to free up the memory from those object which are no loger 
in used.

metadata: Metadata is information about a PE(Portable Executable)means information about Executable file