Showing posts with label .net framework. Show all posts
Showing posts with label .net framework. Show all posts

Wednesday, February 19, 2014

.NET Framework 4 Features

Background garbage collection:
  • Provides background garbage collection 
  • Provide better performance.
  • It replaces concurrent garbage collection.
ETW (event tracing for windows):
  • This determines processor usage and memory usage estimates per app domain.

DLR (dynamic language run-time):
  • Support with System.Dynamic namespace. 
  • DLR built on top of CLR
  • DLR supports dynamic languages (IronPython, IronRuby)

Parallel programming:
  • Parallel programming is introduced
  • PLINQ
  • AsParallel 

Tuple:
  • Data structure consists of multiple parts
  • System.Tuple
  • Maximum of 8 items supported

BigInteger: is introduced with 8 byte storage size. int is 4 byte.


Reference: core new features and improvements


ASP.NET:


New Chart control
:


Routing:
  • Built-in support for routing. 
  • No need to specify physical file names.
Session:
  • Introduced compression option for out-process session state (state server/ SQL Server)

JQuery:
  • is included in script folder


Thursday, June 23, 2011

Satellite assembly

  • Satellite assemblies can only contain resources(.resources files/.resx files)
  • They cannot contain any executable code.
  • Satellites are loaded by a .NET class called System.Resources.ResourceManager.

  • It helps you to localize your assembly
  • For example, use different strings for different locales

  • One of the application of satellite assembly is multi language support
  • ie, keep separate resource file for each languages and load data from the resource files

  • Satellite assemblies can be installed in the GAC
http://www.codeproject.com/KB/aspnet/SatelliteAssemblies.aspx

Tuesday, May 18, 2010

.net difference between throw and throw ex

  • stack information is truncated if we are using throw ex
  • where as stack information gets preserved in throw

throw ex - throw
throw  - rethrow


class Program
    {
        static void Main(string[] args)
        {
            A aa = new A();
            aa.Method1();
        
            Console.Read();
        }
    }

    class A
    {
        public void Method1()
        {
            try
            {
                B bb = new B();
                bb.Method2();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
    }

    class B
    {
        public void Method2()
        {
            try
            {
                C cc = new C();
                cc.Method3();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

    class C
    {
        public void Method3()
        {
            try
            {
                throw new InvalidOperationException();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
        }
    }
 


throw
at CatchSample.C.Method3() in C:\temp\oops\oops\CatchSample\Program.cs:line 60
at CatchSample.B.Method2() in C:\temp\oops\oops\CatchSample\Program.cs:line 45
at CatchSample.A.Method1() in C:\temp\oops\oops\CatchSample\Program.cs:line 25

throw ex
at CatchSample.B.Method2() in C:\temp\oops\oops\CatchSample\Program.cs:line 45
at CatchSample.A.Method1() in C:\temp\oops\oops\CatchSample\Program.cs:line 25

NoteStackTrace information is lost in case of throw ex


Reference:

http://aspadvice.com/blogs/joteke/archive/2004/04/15/2277.aspx

http://geekswithblogs.net/sdorman/archive/2007/08/20/Difference-between-quotthrowquot-and-quotthrow-exquot-in-.NET.aspx

Monday, May 17, 2010

Accessing COM object from .net

  • .NET COM interop allows to use existing COM object in .net without modifying original component
  • First step is to import relevant COM types using COM interop utility.
  • Tlbimp.exe is the utility to import COM types to managed application.
  •  

Reference: http://msdn.microsoft.com/en-us/library/aa645736%28VS.71%29.aspx

Tuesday, April 27, 2010

delegate & multicast delegate

Delegate is like function pointer.

  • Delegate used to invokes a function.
  • Multicast delegate used to invoke more than one function.

class demo
    {
        // delegates are used to invoke function
        delegate int mathdelegate(int a, int b);
        
        public demo()
        {
            mathdelegate objDelegate = new mathdelegate(this.add);
            int result = objDelegate(10, 20);
            Console.WriteLine(result);


            //multicast delegates are used to invoke more than one function
            objDelegate += new mathdelegate(sub);
            result = objDelegate(30, 10);
            Console.WriteLine(result);

            objDelegate += new mathdelegate(mul);
            result = objDelegate(30, 10);
            Console.WriteLine(result);

            
        }

        public int add(int a, int b)
        {
            return a + b;
        }

        public int sub(int a, int b)
        {
            return a - b;
        }

        public int mul(int a, int b)
        {
            return a * b;
        }
    }

Thursday, January 28, 2010

Why name JIT?

.net compiler convert source code into intermediate language during compilation. this is also called as Microsoft intermediate language(MSIL).
Its the job of the JIT compiler to take MSIL and convert it to native code at run time.


.net will not convert all MSIL code into native code at once. Because it is time and space consuming. Some part of the .net code never executes. So there is no need to keep this code in the memory. This is resource consuming.


So .net came up with an approach called JIT compilation, it converts MSIL to native code on demand at application runtime. So the name JUST IN TIME COMPILING

Wednesday, January 6, 2010

Measuring execution time in C#

How to measure a method's execution time without using timer?

Use DateTime and TimeSpan classes in .net framework.

public void sampleMethod()
{
DateTime starttime = DateTime.Now;
//
//......
//do code here
//......
DateTime endtime = DateTime.Now;
TimeSpan duration = endtime - starttime;
string time = duration.Hours + ":" + duration.Minutes + ":" + duration.Seconds + ":" + duration.Milliseconds;
}

Wednesday, December 2, 2009

Const vs ReadOnly in .net

Const
  • It is also called as "Compile time constant"
  • Const can be assigned at variable initialization
  • Once assigned value cannot be changed
ReadOnly
  • "Runtime constant"
  • ReadOnly field can be assigned at variable initialization and in constructor
  • Value can be changed in constuctor

Sample

    class ReadonlyConstant
    {
        private const int x=10;     //compile time constant
        private readonly int y=20;  //runtime constant

        public ReadonlyConstant()
        {
            Console.WriteLine("\n***Const Vs ReadOnly***");
            Console.WriteLine("Const x before initialization=" + x);
            Console.WriteLine("ReadOnly y before initialization=" + y);



            //The left-hand side of an assignment must be a variable, property or indexer
            //x = 20;   // value cannot be changed in constructor

            y = 110;    // value can be changed in constructor   

            Console.WriteLine("Const x after initialization=" + x);
            Console.WriteLine("ReadOnly y after initialization=" + y);
        }

        //public int IncrementY
        //{
        //    //A readonly field cannot be assigned to (except in a constructor or a variable initializer)
        //     set { y++; }
        //}
    }

    Thursday, November 12, 2009

    Anonymous method

    • Anonymous method
    - Its a .net 2.0 feature
    -We can create nameless methods, which can be called using delegates
    • Why Anonymous methods?
     In some cases we are forced to create a class or method just for the sake of using delegates. We can avoid it using anonymous method.


    Real time example:

    • Button click event implementation in windows form is handled using anonymous method:

                //
                // button1
                //
                this.button1.Location = new System.Drawing.Point(38, 116);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                //this.button1.Click += new System.EventHandler(this.button1_Click);

                this.button1.Click += delegate(object sender, System.EventArgs e)
                {
                    System.Windows.Forms.MessageBox.Show("Invoked using anonymous method!!"); 
                };

    String vs StringBuilder

    • String vs StringBuilder
    String
    - Immutable
    - Every time a change happens in string, a new object is getting created in memory
    - In situation, you need to make repeated modification to string, its an overhead.


    System.Text.StringBuilder
    - Mutable
    - Advantage: Performance boost while doing string concatanation(use Append method)