Search | View Active Threads | View New Posts
Current Time: 02:24 AM

 

+ Reply to Thread
Results 1 to 5 of 5
  1. #1

    Thumbs up What is a Static Constructors?

    Special constructor and gets called before the first object is created of the class.

    The time of execution cannot be determined, but it is definitely before the first object creation - could be at the time of loading the assembly.

    Static constructors might be convenient, but they are slow. The runtime is not smart enough to op imize them in the same way it can optimize inline assignments.
    The static constructor for a class executes before any of the static members for the class are r f r nc d.

    The static constructor for a class executes after the static field initializers (if any) for the class.

    A static constructor cannot be called directly.

    The user has no control on when the static constructor is executed in the program

    Example - When the class is using a log file and the constructor is used to write entries to this file.

  2. #2
    Join Date
    Nov 2017
    Posts
    36

    static constructor

    A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced. C# class SimpleClass { // Static variable that must be initialized at run time.

  3. #3
    Join Date
    May 2019
    Location
    Bangalore
    Posts
    107
    Static constructors are used to initializing the static members of the class and implicitly called before the creation of the first instance of the class. Non-static constructors are used to initializing the non-static members of the class.


    Preschool in K Narayanpura | Preschool & Day Care in K Narayanpura | Top 10 Play Schools in K Narayanpura | Best Pre-Nursery in Thanisandra | Best Day Care Centers in Kothanur |
    Preschool in Nagavara | Top Play schools in K Narayanpura

  4. #4
    Join Date
    May 2018
    Posts
    131
    A static constructor is a constructor declared using a static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.

    Example :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Difference {
    class Demo {
    static int val1;
    int val2;

    static Demo() {
    Console.WriteLine("This is Static Constructor");
    val1 = 70;
    }

    public Demo(int val3) {
    Console.WriteLine("This is Instance Constructor");
    val2 = val3;
    }

    private void show() {
    Console.WriteLine("First Value = " + val1);
    Console.WriteLine("Second Value = " + val2);
    }

    static void Main(string[] args) {
    Demo d1 = new Demo(110);
    Demo d2 = new Demo(200);
    d1.show();
    d2.show();
    Console.ReadKey();
    }
    }
    }

    Best Astrologer in Toronto | Top Astrologer in Toronto | Best Indian Astrologer in Toronto | Best Astrologer in Canada | Indian Astrologer in Canada | Best Astrology Services in Canada | Best Psychic Astrologer in Toronto

  5. #5

    Mvno Consulting

    A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  

Sponsors

Domain Escrow Services
Trellian Direct Search Network
Above.com Domain Registrar, Marketplace and Revenue Optimizer

Industry Events

11-14 August 2019
Affiliate Summit East
New York, NY

4-6 March 2019
LeadsCon
Las Vegas

15-18 September 2018
MERGE 2018
Orlando, FL

Poll

How do you invest in domains?
to see the Poll results!
DomainState.com
Domain Tools | Domain Directory | Registrar Stats | Domain Glossary | Industry Events | FAQ | Members | Terms | RSS | Link To Us | Advertise | Contact Us
Other Related Trellian Services:
Above.com Registrar  |  Above.com Marketplace  |  Above.com Domain Manager  |  Free Search Toolbar  |  Free Webpage Builder  |  Keyword Research
Direct Search Navigation  |  Search Engine Submission and SEO Tools
Copyright © 2002 DomainState.com a Trellian Company 2014 Bronze Sponsor - Internet Commerce Association