Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Sunday, May 4, 2014

C# Parameter Modifiers

Here lets discuss about the various Parameter modifiers that can be used to manage how arguments are passed to methods.

  • Default by Value Parameter : If we are not specifying any Parameter Modifier for an argument, by default it is set to Value Parameter. Since we are having Value types, the invoked method will be working on a copy of the original data. This can be better explained with the example as given below
Here you can see that the values are not changed even after the invoked method has changed the values. 
  • The out modifier :Out modifier is useful in scenarios where we need to return more than one values. Below example supports this scenario.
The invoking  method should set the value to the out parameter.
  • The ref modifier : The reference parameter modifier is used in scenarios where we need to change the values in the invoked methods. Unlike the out modifier , here we need to initialize the ref parameters before we pass to any method. The below example better explains the same.



  • The params modifier : We can use params modifier to pass array of similar types as arguments to a method as a single logical parameter. If we specify the params modifier , we can pass the parameters as comma delimited arguments. Below example better explains the same as given below
  • The optional modifier : The optional parameter modifiers are helpful in allowing the caller with the flexibility of passing only required parameters. The below example illustrate the concept


  • Named Parameters : Named modifier allows you to pass the parameters in any order to a method. This provides a readable and a cleaner code. But named parameters has got a performance draw back.

So here we have defined various C# Parameter modifiers.



Saturday, May 3, 2014

Intrinsic Data Types of C#

C#
CLS Compliant
System Type
Range
Definition
bool
Y
System.Boolean
T or F
True or False
sbyte
N
Syste.Sbyte
-128 to 127
Signed 8 bit number
byte
Y
System.Byte
0 to 255
Unsigned 8 bit number
short
Y
System.Int16
-32768 to 32767
Signed 16 bit number
ushort
N
System.Uint16
0 to 65535
Unsigned 16 bit number
int
Y
System.Int32
-2147483648 to 2147483647
Signed 32 bit number
uint
N
System.Uint32
0 to 4294967295
Unsigned 32 bit number
long
Y
System.Int64
-9223372036854775808 to 9223372036854775807
Signed 64 bit number
ulong
N
System.Uint64
0 to 18446744073709551615
Unsigned 64 bit number
char
Y
System.Char
U+0000 to U+ffff
Single 16 bit Unicode character
float
Y
System.Single
-3.4 1038 to +3.4 1038
32 bit floating point number
double
Y
System.Double
+-5.0 10-324 to +-1.7 10-308
64 bit floating point number
decimal
Y
System.Decimal
(-7.9x 1028 to -7.9x 1028)/(100 to 28)
128 bit signed number
string
Y
System.String
Limited
Set of unicode characters
object
Y
System.Object
No limit
Base class

Common Language Runtime

Runtime can be defined as a collection of services that are required to execute a given compiled unit of code.
.NET Runtime provides a single, well defined runtime layer that is shared across all.NET aware languages and is called as Common Language Runtime a.k.a. CLR.

Apart from code execution , CLR provides memory management, thread management, security management, code verification and compilation.

Lets discuss the roles of CLR as given below

Base Class Libraries : This provides class libraries required for an application in .NET world. CLR converts the source code into an intermediate language called Microsoft Intermediate Language (MSIL).

Thread Support: CLR manages the parallel execution of code via threading.

Code Manager : CLR manages the compiled Intermediate Language

Garbage Collector
Garbage Collector handles automatic memory management and it will release memory of unused objects in an application, this provides automatic memory management.

CLSCommon Language Specification (CLS) is defined as a set of rules that describes the minimal and complete set of features a given .NET aware compiler should support. 

CTSCTS defines how various types are declared, used and managed in Common Language Runtime in .NET world

Security Engine: It enforces security permissions at code level security, folder level security, and machine level security using Dot Net Framework setting and tools provided by Dot Net.

Friday, May 2, 2014

Common Type System Overview

In .NET world, Type refers to a generic term used to represent Class, Interface, Enumeration , Delight etc. Whenever we are building any solution around .NET we do interact with these types. So lets define CTS aka Common Type System as "CTS defines how various types are declared, used and managed in Common Language Runtime in .NET world"

  • CTS helps in cross language interaction
  • Provides an Object  oriented model
  • Defines the rules that languages should follow for language interaction.
  • Provides a Base class library that contains primitive data types.
Types can be literally classified as Value Types and Reference Types. Lets define the classification as follows 
Value Types
Value types are data types whose objects are represented by the object's actual value. If an instance of a value type is assigned to a variable, that variable is given a fresh copy of the value.

Reference Types:
Reference types are data types whose objects are represented by a reference (similar to a pointer) to the object's actual value. If a reference type is assigned to a variable, that variable references (points to) the original value. No copy is made.

CTS supports the following categories of types
  • Classes : Classes are Reference types. It defines the operation an object can perform and the data that object contains
  • Structures : Structures refers to Value types. It derives from System.ValueType. Used extensively in low memory requirements.
  • Enumerations : Enumeration are Value types. It derives from System.Enum. It supplies alternate names for the values of an underlying primitive type.
  • Interfaces : Interfaces are contracts which contains declarations of method or properties which an implementing class will do the implementation.
  • Delegates : Delegates are Reference types which is a functional pointer used in event handlers and call back functions in .NET.
CTS type definitions includes the following
  • Any attribute defined on type
  • Type accessibility
  • Type name
  • Types base types
  • Any interface defined by the types
  • Definition for each type members
Type members defines the behavior and state of a types. The following are type members
  • Fields
  • Properties
  • Methods
  • Constructors
  • Events
  • Nested types

Assemblies in CLR

Assemblies are the building blocks of .NET framework applications. An assembly is a collection of similar types and resources that are build to work together and form a logical unit of functionality. Assembly provides the type implementation details for CLR. Assembly forms the fundamental part of deployment,version control,reuse,activation scoping and security permissions.

.NET binaries does not contain platform specific instructions. But instead it contains the paltform agnostic Intermediate Language (IL). It is also known as Microsoft Intermediate Language. All .NET aware compilers produces nearly identical CIL instructions.

JIT (Jitter) compiler compiles the CIL code into meaningful CPU instructions. JIT is flexible enough to execute in different tartgeted environments.

.NET Type Metadata : In addition to CIL instructions, .NET assembly contains metadata. It refers to each and every type, members of each type etc. Metadata is used by numerous aspects of .NET runtime environment.

Assembly Manifest: .NET Assembly also contains metadata that describes the assembly itself. This is called as Manifest. Manifest documents all external assemblies required by the current assembly, version number , copy right information etc.


Thursday, May 1, 2014

.NET Platform

Initially before the .Net Platform were introduced, software development was done using COM (Component Object Model) in Windows operating systems. It was so popular just because of the language independency and reusability across different languages. The demerits of this model was the complexity in infrastructure and deployment.
Later Microsoft introduced the .NET platform in early  2002 and became so popular till date due to its features and flexibility in usage. Lets jote down the advantages of the .NET platform as follows
·         Interoperability
·         Support different languages. .NET family consists of C#,VB,F# etc.
·         Common Language Runtime caters to different .NET languages
·         Common Type System and Common Language Specifications supporting the cross language interactions
·         Base Class libraries shared by all .NET languages

·         Simplified application deployment and maintenance.


We can disucss about the above blocks indvidually in my later blog posts. Now lets see the major enhancements in the history of .NET frameworks and IDE releases.
·         .NET 1.0
o   Introduced with Visual Studio .NET.
o   Intriduced CLR 1.0
o   Support for OOPs in Web application development
o   DLL class libraries
·       . NET 1.1
o   Introduced with Visual Studio .NET 2003
o   Enhancements to ASP.NET and ADO.NET
o   Security enhancements
o   Support for ODBC and databases
·         .NET 2.0
o   Introduced with Visual Studio .NET 2005
o   CLR 2.0
o   Generics and Collections
o   Partial Class
o   Nullable Types
o   Anonymous methods
·         .NET 3.0
o   Introduced with Visual Studio .NET 2005
o   WPF
o   WCF
o   WF
·         .NET 3.5
o   Introduced with Visual Studio .NET 2008
o   Built in Ajax support
o   LINQ
o   Multi targeting Framework support
·         .NET 4.0
o   Introduced with Visual Studi .NET 2010
o   CLR 4.0
o   Managed Extensibility Frameowrk
o   Task parallel library
o   Dynamic Language Runtime
·         .NET 4.5
o   Intriduced with Visual Studio 2012
o   Enhancements to CLR 4.0
o   Async support
o   Support for Windows Store Apps

Keep watching this space for more blogs on C# in the coming days....

Installing ASP.NET MVC

Installing ASP.NET MVC Before we dive deep into the ASP.NET MVC, let’s install it our development machine. This is very straight forwa...