GeekInterview.com
Series: Subject: Topic:

C# Interview Questions

Showing Questions 1 - 20 of 460 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

In a multilevel hierarchy how are the constructors are called

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) topdownb) bottomupc) none

Answered by: Damian on: Apr 5th, 2014

Bottomup "c# using System; public class A // This is the base class. { public A() { // Executes some code in the constructor. Console.WriteLine("Base cons...

Answered by: Sivavt on: Mar 26th, 2012

Order of call: From child to parent
Order of execution: From parent to child

What are constructors in .Net

Asked By: Bhanu | Asked On: Jun 21st, 2013

Answered by: Raj on: Nov 28th, 2013

Constructor is a special type of method which intialized in the class, which has same name of the class. it has no any return value.

Code
  1. public void class
  2. {
  3. public class // This is constructor, which no has return type.
  4. {
  5. }
  6. }

Answered by: Ranjit jana on: Aug 7th, 2013

Constructor is a special type of method use to initialize the object of its existing class.Its declare same name as its existing class without return type.

How to handle exceptions without using try catch finally

Asked By: Nitesh | Asked On: Sep 27th, 2006

Answered by: Chandrashekhar Upadhyay on: Nov 16th, 2013

using (SqlConnection con = new SqlConnection())
{
try
{
con.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

Answered by: vpote on: Apr 15th, 2013

The best way to do this would be doing the same in global.asax application_error method.

Thanks
Vijay

How can I check whether a dataset is empty or not in c#.Net

Asked By: Ravinder Nain | Asked On: Feb 2nd, 2006

Answered by: Chandrashekhar on: Nov 16th, 2013

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlString, sqlConn);
da.Fill(ds);

It is work i sure

Answered by: Bucked Naked on: Sep 11th, 2013

Wrong. Try this for better results:

Code
  1. DataSet ds = <get a dataset somehow>;
  2. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows > 0)
  3. {
  4.     // There is something in the DataSet.
  5. }

How do you make a class not instantiable

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) making class as abstractb) having a priVATe constructorc) making the class sealedd) both a & b

Answered by: Chandrashekhar on: Nov 16th, 2013

static class FEATURE are: They only contain static members. They cannot be instantiated. They are sealed. They cannot contain Instance Constructors a static class is that the compil...

Answered by: kunal on: Jun 12th, 2013

A and B

The following code fails. Why?

Asked By: Farhan | Asked On: Nov 12th, 2007

Int a = 5; int b = 5; object oa = a; object ob = b; debug.Assert(oa == ob, "oa is not equal ob");

Answered by: chidski on: Oct 17th, 2013

Given code fails bcoz. debug result is wrong.. Please see below int a = 5; int b = 5; object oa = a; object ob = b; Debug.Assert(oa != ob...

Answered by: iaskalyani45 on: Jan 18th, 2013

nice answer peter

When to use string classes

Asked By: sushil_gupta | Asked On: Jan 17th, 2011

When we have string builder which are mutable why we need immutable string classes in c#.

Answered by: Denial on: Aug 14th, 2013

String: String are immutable that is every time you make changes to a string object, the string is destroyed and a new string is created with modifications you applied to previous string. All this is ...

Answered by: Sivavt on: Mar 25th, 2012

String is immutable, meaning, if there is any change in the string value, run time allocates new memory & assign it to the string reference. For the programmer, it looks like the same string but inter...

Which of the following statements is not true for interfaces

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) interface definitions does not have implementationb) interfaces must be declared as publicc) interfaces can be instantiatedd) interface does not have constructorsexplanation: interfaces can only be implemented by inheriting and they can not be instantiated

Answered by: TheDentist on: Apr 23rd, 2013

C is the correct answer. Interfaces dont have constructors so they cant be instantiated.

http://msdn.microsoft.com/en-US/library/vstudio/ms173156.aspx

Answered by: michellext on: Sep 13th, 2012

C) Interfaces can be instantiated

Can we write dotnet console program in UNIX

Asked By: narsimhareddygajjela | Asked On: Jul 30th, 2012

Can we write dotnet console program in UNIX ? If yes give one example.

Answered by: TheDentist on: Apr 23rd, 2013

If you write in Java then the application will run in a JRE on UNIX but you have to compile the application on Windows first. Then deploy it to UNIX.

Answered by: vpote on: Sep 2nd, 2012

You can use mono .net for this

Which of the following statement is invalid with regards to constructor

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) constructors should have the same name as class nameb) constructors have to be public so that class can be instantiatedc) constructors can not be overloadedexplanation: constructors can be overloaded with different parameters

Answered by: tmounika on: Nov 1st, 2012

all the three statements are true...

Answered by: Viky on: Oct 4th, 2012

The correct answer is B: as constructors need not be public we can have private constructors also for instance a singleton object has a private constructor

If a.Equals(b) is true then a.Gethashcode & b.Gethashcode must always return same hash code

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) trueb) false

Answered by: Alexandre on: Oct 13th, 2012

Not necessarily. Actually GetHashCode() can always return the same value... :-) Say "1". And everything will work well. Just Hashtable with such a key will not be efficient. Keys in the hashtable are ...

Answered by: Deadbeef66 on: Oct 29th, 2011

FALSE

Both Equals() and GetHashCode() can be overridden by the developer for user-defined classes, so there is no guaranteed behavior.

Program on 3d matrix using random function print the o/p in file.

Asked By: k.sampath kumar | Asked On: Jun 1st, 2012

Program on 3d matrix using random function print the o/p in file find the even,odd,prime numbers from above output file. please do needful help thank you

Why strings are immutable?

Asked By: Rohit Sharma | Asked On: Apr 21st, 2006

Answered by: Jeevan on: Apr 20th, 2012

People, please read the question before answering, don't just answer "Why" is the question - not "how".

Answered by: LordAlex on: Nov 6th, 2011

String is an array of bytes.
When are you ave to change it, you have to create the new one; because the string is always considered as a constant.

My switch statement works differently! Why?

Asked By: Interview Candidate | Asked On: Sep 13th, 2004

C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in c#: switch(x){case 0:// do somethingcase 1:// do something in common with 0default:// do something in common with//0, 1 and everything elsebreak;}to achieve the same effect in c#, the...

Answered by: Sivavt on: Apr 4th, 2012

Folks:

Empty cases allowed to fall through in C#.

Answered by: TheOutlander on: Aug 20th, 2010

Most of the other answers are right, but there is a caveat.

Empty cases are allowed to fall through. However, the last case statement always needs a break - empty or not.

By declaring a base class function as virtual we allow the function to be overridden in subclasses

Asked By: Interview Candidate | Asked On: Jan 1st, 2006

A) trueb) falseexplanation: if a function is declared virtual it needs to be overridden in subclass

Answered by: Sivavt on: Mar 29th, 2012

It is not mandatory for a derived class to override the virtual base method. Nevertheless, derived class can opt to override the virtual base method to redefine the functionality.

Answered by: Dinesh M Yadav on: Aug 28th, 2011

The answer is A) TRUE. If you declare a virtual method in a class , its not mandatory to override it in the sub class. However, In case of abstract class, the answer would be B) False since if you ...

C# sealed variables

Asked By: aarruunnaa | Asked On: Dec 2nd, 2007

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() { ...

Answered by: Sivavt on: 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.

Answered by: Rajeeva on: 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.

Exception handling

Asked By: Suganya | Asked On: Aug 20th, 2011

What is the necessary for "throws" and "throw" in exception handling?? even though the exception has been thrown automatically and being handled by try and catch block..

Answered by: Sivavt on: Mar 29th, 2012

no throws in C#.

throw is used to re-throw exceptions

Answered by: Suresh Jayaraman on: Sep 23rd, 2011

if we have different layers like Dataaccess layer,Business layer ,Presentation layer. The error is in DataAccess layer,that error should come to presentation layer and we can show that error in messa...

Following are the collections in c#:

Asked By: Interview Candidate | Asked On: Nov 27th, 2005

Skill/topic: advanceda) structsb) enumc) dictionariesexplanation: ans. B & c. A isnít a collection .

Star Read Best Answer

Editorial / Best Answer

Answered by: LordAlex

View all answers by LordAlex

Member Since Nov-2011 | Answered On : Nov 5th, 2011

All collections directly or indirectly should implement the ICollection interface or the ICollection(Of T) generic interface. If you check System.Array you will see ICollection interface in there. Correct answer is C, it doesn't matter that there are methods that can provide arrays of Names and Values. Because if you are reasoning like this, it means bject.ToString().ToCharArray() cause all classes are being collections.

Answered by: Sivavt on: Mar 27th, 2012

C. Dictionary

Enum is not a collection but a distinct type like struct

Answered by: LordAlex on: Nov 5th, 2011

All collections directly or indirectly should implement the ICollection interface or the ICollection(Of T) generic interface. If you check System.Array you will see ICollection interface in there. Co...

Object oriented and object based language

Asked By: abuhurera farooqe | Asked On: Aug 2nd, 2008

Explain what are object oriented language and object based language

Star Read Best Answer

Editorial / Best Answer

Answered by: Aarthy_SP

View all answers by Aarthy_SP

Member Since Dec-2008 | Answered On : Dec 10th, 2008

Any langauge based on encapsulation concpet and operations with the objects are called as Object Based language. Exmaple : VB is a Object based and not an Object oriented

Any langauge based on encapsulation concept and operations with the objects and also dealing with the inheritance and polymorphism are called as Object Oriented language. Exmaple : C++,C#

Answered by: Sivavt on: Mar 27th, 2012

Object based languages do not support inheritance & dynamic binding. Example, VB

Answered by: LordAlex on: Nov 5th, 2011

Object Oriented - supports of using the objects.
Object Based Language - all data types are objects, based on single type object primitive.

When do you absolutely have to declare a class as abstract ?

Asked By: Interview Candidate | Asked On: Sep 15th, 2004

(as opposed to free-willed educated choice or decision based on uml diagram)?  when at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

Answered by: Sivavt on: Mar 26th, 2012

If any of the methods do not have implementation.

Answered by: Devender Thadkapalli on: Nov 28th, 2011

When you do not want to create an object of the class and want to provide some abstract implementation

ex: Class HumanBeing. No Point of creating a class human being. You can create Men or Women out of it an create an object of the derived class

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.