Skip to main content

Posts

Showing posts from 2014

Deligates

Delegates A delegate is a type that represents references to methods with a particular parameter list and return type.When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance. When and Why to use Delegates A delegate can be seen as a placeholder for a/some method(s). By defining a delegate, you are saying to the user of your class "Please feel free to put any method that match this signature here and it will be called each time my delegate is called". Typical use is of course events. All the OnEventX delegate to the methods the user defines. Delegates are useful to offer to the user of your objects some ability to customize their behaviour. Most of the time, you can use other ways to achieve the same purpose and I do not believe you can ever be forced to create delegates. It is just the easiest way in some situations t

Web Services

Web Services A Web Service is programmable application logic accessible via standard Web protocols. One of these Web protocols is the Simple Object Access Protocol (SOAP). SOAP is a W3C submitted note (as of May 2000) that uses standards based technologies (XML for data description and HTTP for transport) to encode and transmit application data. Consumers of a Web Service do not need to know anything about the platform, object model, or programming language used to implement the service; they only need to understand how to send and receive SOAP messages (HTTP and XML). Soap Message A SOAP message consists of several elements, most notably an envelope. The envelope encapsulates the data transmitted within the SOAP message. Below is a simple SOAP message complete with HTTP headers: POST /demo/MSDN/PerfCounter.asmx HTTP/1.1 Connection: Keep-Alive Content-Length: 150 Content-Type: text/xml Host: localhost User-Agent: MS Web Services Client Protoc

Value Type and Reference Types

Value Type A data type is a value type if it holds the data within its own memory allocation. Value types include the following: All numeric data types Boolean, Char, and Date All structures, even if their members are reference types Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong Every structure is a value type, even if it contains reference type members. For this reason, value types such as Char and Integer are implemented by .NET Framework structures. You can declare a value type by using the reserved keyword, for example, Decimal. You can also use the New keyword to initialize a value type. This is especially useful if the type has a constructor that takes parameters. An example of this is the Decimal(Int32, Int32, Int32, Boolean, Byte) constructor, which builds a new Decimal value from the supplied parts. Reference Types A reference type contains a pointer

MethodInvoker Delegate

MethodInvoker Delegate public delegate void MethodInvoker() Remarks MethodInvoker provides a simple delegate that is used to invoke a method with a void parameter list. This delegate can be used when making calls to a control's Invoke method, or when you need a simple delegate but do not want to define one yourself. Examples The following code example demonstrates how to use a MethodInvoker to call a method that updates the title bar of the application form. C# public partial class Form1 : Form { public Form1() { // Create a timer that will call the ShowTime method every second. var timer = new System.Threading.Timer(ShowTime, null, 0, 1000); } private void ShowTime(object x) { // Don't do anything if the form's handle hasn't been created // or the form has been disposed. if (!this.IsHandleCreated && !this.IsDisposed) return;

Function pass by value vs. pass by reference

Function pass by value vs. pass by reference I will call what you are passing in a to a function the actual parameters, and where you receive them, the parameters in the function, the formal parameters. They are also called actual and formal arguments. When passing parameters, what it is called and what happens can be confusing. It is less essential that you call it the "correct" thing than you know exactly what is happening. It is critical to have a good mental model, a valid memory picture of the process. Recall that when you call a function, a chunk of memory called an activation record is allocated. Critical to the discussion here is that this memory holds the formal parameter values and function local variables. By definition, pass by value means you are making a copy in memory of the actual parameter's value that is passed in, a copy of the contents of the actual parameter. Use pass by value when when you are only "using" the paramet

Serializing Objects in C#

Serializing Objects in C# In simple words serialization is a process of storing the object instance to a disk file. Serialization stores state of the object i.e. member variable values to disk. Deserialization is reverse of serialization i.e. it's a process of reading objects from a file where they have been stored. In this code sample we will see how to serialize and deserialize objects using C#.

C# Basics

1) C# Basics Access Specifiers public The type or member can be accessed by any other code in the same assembly or another assembly that references it. private The type or member can be accessed only by code in the same class or struct. protected The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class. internal The type or member can be accessed by any code in the same assembly, but not from another assembly. protected internal The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

Features of Interface

Features of Interface     An interface doesn't provide inheritance like a class or abstract class but it only declare members which an implementing class need to be implement.     It cannot be instantiated but it can be referenced by the class object which implements it. Also, Interface reference works just like object reference and behave like as object.         IStore IObjStore = new Document();         ICompress IObjCompress = new Document();     It contains only properties, indexers, methods, delegates and events signature.     It cannot contains constants members, constructors, instance variables, destructors, static members or nested interfaces.     Members of an interface cannot have any access modifiers even public.     Implicitly, every member of an interface is public and abstract. Also, you are not allowed to specify the members of an interface public and abstract or virtual.     An interface can be inherited from one or more interfaces.     An interface can extend a

Features Of Abstract Class

Features of Abstract Class     An abstract class cannot be instantiated.     An abstract class contain abstract members as well as non-abstract members.     An abstract class cannot be a sealed class because the sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.     A non-abstract class which is derived from an abstract class must include actual implementations of all the abstract members of parent abstract class.     An abstract class can be inherited from a class and one or more interfaces.     An Abstract class can has access modifiers like private, protected, internal with class members. But abstract members cannot have private access modifier.     An Abstract class can has instance variables (like constants and fields).     An abstract class can has constructors and destructor.     An abstract method is implicitly a virtual method.     Abstract properties behave like abstract methods.     An abstract class cannot b

WCF REST Note

Background Overview of REST REST stands for Representational State Transfer . This is a protocol for exchanging data over a distributed environment. The main idea behind REST is that we should treat our distributed services as a resource and we should be able to use simple HTTP protocols to perform various operations on that resource. When we talk about the Database as a resource we usually talk in terms of CRUD operations. i.e. Create, Retrieve, Update and Delete. Now the philosophy of REST is that for a remote resource all these operations should be possible and they should be possible using simple HTTP protocols. Now the basic CRUD operations are mapped to the HTTP protocols in the following manner: GET : This maps to the R(Retrieve) part of the CRUD operation. This will be used to retrieve the required data (representation of data) from the remote resource. POST : This maps to the U(Update) part of the CRUD operation. This protocol will update the current re

Passing Data from View to Controller Using Ajax Example Jquery

Jquery       $ ( '#btnSaveComments' ). click ( function () { var comments = $ ( '#txtComments' ). val (); var selectedId = $ ( '#hdnSelectedId' ). val (); $ . ajax ({ url : '<%: Url.Action("SaveComments")%>' , data : { 'id' : selectedId , 'comments' : comments }, type : "post" , cache : false , success : function ( savingStatus ) { $ ( "#hdnOrigComments" ). val ( $ ( '#txtComments' ). val ()); $ ( '#lblCommentsNotification' ). text ( savingStatus ); }, error : function ( xhr , ajaxOptions , thrownError ) { $ ( '#lblCommentsNotification' ). text ( "Error encountered while saving the comments." ); } }); });     Controller    [ HttpPost ] public ActionResult SaveComments ( int id , string com

System.Web.Mvc Namespace

System.Web.Mvc Namespace Classes   Class Description AcceptVerbsAttribute Represents an attribute that specifies which HTTP verbs an action method will respond to. ActionDescriptor Provides information about an action method, such as its name, controller, parameters, attributes, and filters. ActionExecutedContext Provides the context for the ActionExecuted method of the ActionFilterAttribute class. ActionExecutingContext Provides the context for the ActionExecuting method of the ActionFilterAttribute class. ActionFilterAttribute Represents the base class for filter attributes. ActionMethodSelectorAttribute Repr