Get benefited from interview Q/A and Online Test section. Subscribe to this blog to get updates directly in your mail box.
Best View in Google Crome, Mozilla firefox or IE 7 or above
Showing posts with label c sharp interview questions. Show all posts
Showing posts with label c sharp interview questions. Show all posts

Sunday, April 6, 2014

Difference between constructor and method in c#

This is a very basic question mainly asked in Beginner level interviews (1 to 2 years of experience).
The interviewer can twist the question as below as well.


  • Difference between method and constructor in c#
  • Difference between constructor and method in dotnet with example
  • Difference between methods and constructors in object oriented programming


Answer:

Here are few differences between Constructor and methods in bullet points.


Constructor:
1. Name of constructor should be same as class name
2. Constructor is used to initialize class members (variables). It is used to create an instance of  a class.
3. Returns nothing. Hence no return type.
4. Called implicitly at the time of object creation


Method:
1. Name is independent from class name
2. Method is having some functionality. It is used to perform some operations.
3. Must return something. If nothing to return, explicitly return type should be void.
4. Need to be called explicitly


Sunday, June 26, 2011

Find the Bugs in this C Sharp Dotnet Code

Here is another simple C Sharp dotnet interview question.

There is a piece of code in C# Dotnet as written below. The function takes a number array as input and returns the largest number. It has few bugs in it. Find out the bugs and fix them.

Code :

        public static int Largest(int[] list)
        {
            int max = int.MaxValue;

            for (int i = 0; i < list.Length - 1; i++)
                if (list[i] > max)
                    max = list[i];

            return max;
        }

You can post the answers as comments. Thank you.

  © Blogger templates Shiny by Ourblogtemplates.com 2008

Back to TOP