Thursday 13 March 2014

C# Structure

Why C# structures cannot have explicit parameterless constructor?

Answer: structures are value types. value types in C# contains default values. 
example: integer which by default value is numerical zero.

Remember : Structures can contain parametrized constructor.

more on C# structure

  • To define a structure we will use C# keyword called "struct"
  • structure is a value type. (its a protocol)
  • when we instantiated structure , it will be allocated in stack memory.(because all struct is a value type and all value types are will be allocated a stack memory)
  • structure cannot contain destructor.(only class can have destructor) WHY? 

Answer: struct being value type, are not subject to garbage collection. for more click here
  • we cannot use abstract and sealed keyword while defining a structure. C# Struct does not support inheritance.
  • we cannot use protected and protected internal access modifier for structures or structure members because it will not support inheritance.
  • To create an object for structure we don't required to use new operator.(When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.)


C#.NET Interface

C Sharp - Interface

  • By default Interface is Internal
  • All interface members are implicitly public and abstract so the members of the interface never specify access modifier.
  • Interfaces do not have an implementation of members(protocol). so interfaces cannot have data fields and also interfaces do not have constructors.
  • It is illegal to allocate Interface types.
  • Interfaces has read/write properties
  • Interfaces can contain event and indexer definitions.




Monday 24 February 2014

ASP.NET Web API


What is ASP.NET Web API?


ASP.NET Web API is a framework for building web APIs on top of the .NET Framework.

What Model means in ASP.NET Web API?


A model is an object that represents the data in your application. ASP.NET Web API can automatically serialize your model to JSON, XML, or some other format, and then write the serialized data into the body of the HTTP response message. As long as a client can read the serialization format, it can deserialize the object. Most clients can parse either XML or JSON. Moreover, the client can indicate which format it wants by setting the Accept header in the HTTP request message.

What Controller means in ASP.NET Web API?


In Web API, a controller is an object that handles HTTP requests. We'll add a controller that can return either a list of products or a single product specified by ID.


Source