C# Interview Questions

Showing Questions 21 - 28 of 28 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page:
  •  

    Which statement is invalid with regards to Constant

    A) They must be initialized when they are declaredB) The value of the constant must be computable at compile timeC) Constants are not staticD) Constant is a variable whose value can be changed through out it’s life time when it is static.

    Elean0r

    • May 25th, 2011

    Statement D is definitely invalid. Statement C occupies a grey area, since:a) a const field will have the same value in each object of that class; so it appears to? have same effect as a static reado...

  •  

    ByteArray Class

    Write a class called ByteArray that implement allocating, reading and writing to an array of bytes. The runtime environment has a limitation. The maximum continuous memory size that it can allocated is 64k bytes. It can allocate many 64K ( or less) chunks. The ByteArray class should hide this limitation and support allocating arrays larger than 64K as in the following example :ByteArray ba = new ByteArray...

  •  

    What is the difference between const and static read-only?

    The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case a bit, the containing class can only modify it:-- in the variable declaration (through a variable initializer).-- in the static constructor (instance constructors if it's not static).

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Eddie Quiroz

    • Sep 3rd, 2005


    A const must be initialized at the time of its creation. A readonly field can be assigned to once in the class constructor allowing you to pass in the value at run-time. Declaring fields as const protects both you and other programmers from accidentally changing the value of the field. Also note that with const fields, the compiler performs some optimization by not declaring any stack space for the field. The readonly keyword is similar to const, with two exceptions. First, the storage of a readonly field is the same as a regular read-write field, and thus there is no performance benefit. Secondly, readonly fields can be initialized in the constructor of the containing class.

    chandra_123

    • Apr 7th, 2009

    As static read-only variables must be initialized in the static constructor (static constructor cannot have parameters and it cannot be called manually), it is efficient to used const variables over static read-only variables if you know the values at creation of these variables.

  •  

    AutoPostBack Property

    There is Cancel button and OK button on page. When we click Cancel button it skips all validation controls and goes to next page.(a)Page AutoPostback of Cancel is True.(b)Page AutoPostback of Cancel is False.(c)Page AutoPostback of OK is True.(d)Page AutoPostback of OK is False.Which option is correct?

    Star Read Best Answer

    Editorial / Best Answer

    solanki.hr  

    • Member Since Dec-2009 | Dec 10th, 2009


    A button control does not have AutoPostBack property it has click event. so once you click on cancel and if its CausesValidation Property is false it will skips all validations, and if it is true it will validate the controls on the page.

    AutoPostBack property is for say DropDown,textbox etc... whnever you change/enter value/keyed some caharcter in textbox or change your selection in drop down postback will happen if that control's is AutoPostBack property is true, depending on that postback you can fill values or set some values for other controls or you can do some validation against enterd or selcted values.

    e.g. say tehre are 2 drop down. DropDown1 and DropDown2
    DropDown2 is currently holding states of US country as in DropDown1 you have selcted US. Now you want to fill DropDown2 with state value of India.
    Now if
    DropDown1.AutopostBack = True;

    and you change DropDown1's value from Us to India. 
    Page will post back to server and you can fill DropDown2 with Indian States.

    Thanks,
    Solanki  

  •  

    Public Members

    Why do we use properties rather than public members?

    Star Read Best Answer

    Editorial / Best Answer

    netdev  

    • Member Since Oct-2009 | Oct 10th, 2009


    To the user of an object, property and public member may not make much difference with respect to syntax. However, property provides the ability to combine both field and method via the get and set accessors.

    MS Help for C# presents the best answer for using properties:

    Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields.

    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_csref/html/f7f67b05-0983-4cdb-96af-1855d24c967c.htm

    azita2005

    • Apr 1st, 2010

    With Properties, we can implement validation.For example, if we have customer age and we want to add validation on  the age, we can do it with properties.Another benefits of properties is that we can protect a field in a class by reading and writing it through the properties.

    SeeSharp

    • Mar 7th, 2010

    Private data fields of class should not be exposed by making them public. Instead they can made visible using public properties in more controlled manner. Also we can make properties read only or read/write.

  •  

    C# Calender Days

    How to find out how many calender days are there between two dates in c#.net?

    Star Read Best Answer

    Editorial / Best Answer

    wyverex  

    • Member Since May-2008 | May 13th, 2008


    DateTime t1 = new DateTime(2008, 5, 13);

    DateTime t2 = new DateTime(2004, 2, 22);


    TimeSpan span = (t1 > t2 ? t1 - t2 : t2 - t1);


    Console.WriteLine(span.TotalDays);

    ngobeseb

    • Nov 4th, 2009

    Here is the better answer:DateTime fDate = DateTime.Now;int thisDay = fDate.DayOfYear; //if today's date is 31/12/2008, thisDay will be 365 and if today's date is 01/01/2009, thisDay will be 1.Therefore, you can use DayOfYear propery to get the day number in a year.

  •  

    'this' in C#

    Explain about 'this' and where and when it should be used?

    Star Read Best Answer

    Editorial / Best Answer

    Charlito  

    • Member Since Apr-2008 | Apr 3rd, 2008


    The 'this' keyword in C# is used to reference the current class instance.
    It can be optionally used as a qualifier in referencing the fields, properties or methods of the current instance of the class.

    Charlito

    • Apr 3rd, 2008

    The 'this' keyword in C# is used to reference the current class instance.It can be optionally used as a qualifier in referencing the fields, properties or methods of the current instance of the class.

  •  

    Delegates and Generics in c#

    What is the advantage of using delegates and Generics in c# .

    Star Read Best Answer

    Editorial / Best Answer

    sutanu_halder  

    • Member Since Dec-2007 | Apr 18th, 2008


    Advantage of Generic:-

    1. Generics provide type safety without the overhead of multiple implementations.
    Ex. We can create a linked list of string.
        LinkedList<string>linkList=new LinkedList<string>();
    There is no need to inherit from a base type and override members.The linked list is ready

    for immediate use.

    2. There is no need to write code to test for the correct data type because it is enforced

    at compile time. The need for type casting and the possibility of run-time errors are

    reduced.

    3. Generic collection types generally perform better for storing and manipulating value

    types because there is no need to box the value types.

    4. Generic delegates enable type-safe callbacks without the need to create multiple delegate

    classes.

    5.Generic delegates can also be used in dynamically generated code without requiring the

    generation of a delegate type. This increases the number of scenarios in which you can use

    lightweight dynamic methods instead of generating entire assemblies.

    Advantage of Delegate:

    Delegates are managed function pointers. they are type checked and held in spaces that can

    be reclaimed by the memory manager.

Showing Questions 21 - 28 of 28 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page: