Interview Questions for freshers part -2


Q1)difference between array and stack
Ans)
There are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want
------------------------------------------
Q2)Suppose you have a DataTable having 100,000 rows and 50 columns. Now you've create array of perticular column values, how will you do that?
Ans)
It's simple.
for C#
object[] arr = Array.ConvertAll(dataTable.Select(), (DataRow r) => r[]);
for VB
dim arr as Object() = Array.ConvertAll(Of DataRow, Object)(dataTable.Select(), Function(r as DataRow) r());
------------------------------------------------------------
Q3)Can we assign values to read only variables?if yes then how?
Ans)
yes, we can assign values to read only variables either at a time of declaration or in constructors
-------------------------------------------------------------------
4)Difference between Abstract class and interface?
Ans)
1.Through the abstract class we cannot achieve the multiple inheritance in c-sharp. while by interface we can.
2. We can declare the access modifier in abstract class but not in interface. Because by default everything in interface is public
-----------------------------------------------------------------------
5)You can derive an abstract class from another abstract class. In that case, in the child class it is optional to make the implementation of the abstract methods of the parent class....!
Ans)
Select from following answers:
True
False
No Idea
True
If the derived class is also an abstract class then it is not mandatory to implement the abstract method of the parent class.
-------------------------------------------------------------------------------
6)Can you prevent a class from overriding ?
Ans)Yes you can prevent a class from overriding if you define a class as "Sealed " then you can not inherit the class any further.
------------------------------------------------------------------


Q1)difference between array and stack
Ans)
There are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want
------------------------------------------
Q2)Suppose you have a DataTable having 100,000 rows and 50 columns. Now you've create array of perticular column values, how will you do that?
Ans)
It's simple.
for C#
object[] arr = Array.ConvertAll(dataTable.Select(), (DataRow r) => r[]);
for VB
dim arr as Object() = Array.ConvertAll(Of DataRow, Object)(dataTable.Select(), Function(r as DataRow) r());
------------------------------------------------------------
Q3)Can we assign values to read only variables?if yes then how?
Ans)
yes, we can assign values to read only variables either at a time of declaration or in constructors
-------------------------------------------------------------------
4)Difference between Abstract class and interface?
Ans)
1.Through the abstract class we cannot achieve the multiple inheritance in c-sharp. while by interface we can.
2. We can declare the access modifier in abstract class but not in interface. Because by default everything in interface is public
-----------------------------------------------------------------------
5)You can derive an abstract class from another abstract class. In that case, in the child class it is optional to make the implementation of the abstract methods of the parent class....!
Ans)
Select from following answers:
True
False
No Idea
True
If the derived class is also an abstract class then it is not mandatory to implement the abstract method of the parent class.
-------------------------------------------------------------------------------
6)Can you prevent a class from overriding ?
Ans)Yes you can prevent a class from overriding if you define a class as "Sealed " then you can not inherit the class any further.
------------------------------------------------------------------