Answered Questions

  • C# sealed variables

    I have taken a windows application and a button control in it.I want to declare a variable as a sealed and use that variable with in same class as we cannot use in other class. class test { public sealed int x = 5; public void abc() { MessageBox.Show(x.ToString()); } } class best :test { ...

    Sivavt

    • Mar 29th, 2012

    Keyword sealed can be used with class declaration to prevent it from being sub-classed.
    Keyword sealed can be used in method declaration to prevent it from being overridden.

    Rajeeva

    • Sep 4th, 2011


    To restrict users from inheriting the class by sealing the class using "sealed" keyword i.e. no class can be drieved from a sealed class. both Class and Method can be sealed, in that case Method cannot be overridden.

  • Constructors can not be static ?

    Sivavt

    • Mar 25th, 2012

    Yes, there can be a static constructor. It will be at class level & executed just once. It is totally in run-times control & not sure of when this will be executed. But, it is assured that it will be executed before creating instance of the class.

    Aashish Chachra

    • Mar 2nd, 2012

    A class can have only one static constructor. Static constructor can not have any parameter. Static constructor cannot have any access specifier, not even private. It is used to initialize the static ...