C# Interview Questions and Answers (958) - Page 18

Difference between Value types and Reference types ?



Value Types

.Value Types cannot inherit from another class or struct. Value types can only inherit from interfaces

.There is no heap allocation or garbage collection overhead for value-type variables.

.Value types are stored on the stack

.Value type variables directly contain their values


Reference Types

.Reference types can inherit from another class or interface.

.As reference types are stored on the managed heap, they have the over head of object allocation and garbage collection.

.Reference types are stored on the managed heap.

.Reference variables holds only a reference to the location of the object that is created on the managed heap.
Can we have Secured a secured web page using HTTP protocol instead of HTTPS ?



No we can't, if we really want our asp page to be secured we need to use this HTTPS protocol. The overhead of this is the user must and should type HTTPS in his url otherwise the access will be denied.
What is Call By Out parameter?

Call By Out = Call By Ref-Initialization

If the actual parameters initial value are not known while invoking a method then call by out must be used. When using call by out, actual and formal parameter must be decided proceeded without keyword.
When you are using call by out, actual parameters cannot be assigned with any value. Even then it is assigned, it will not be taken by formal parameter.
What are Object Initializers?

The Object initializers are the features for programming concepts which was introduced in C#.Net.

The aim of using Object Initializers is to intializing the accessible fields or properties
of an object without the need to write any parameterized constructor or separate
statements.

Sample:
using System; 

class Student
{
int rollno;
string stdName;

static void Main()
{
Student s = new Student() { rollno=1,stdName="Ramesh" }; //Object Initializer
}
}

What is Window Service? What are the three types of programs required to operate a service?

A window service can be thought of as an executable that does not support a user
interface, and which might not run under the logged - on user account. The service can run without any user being logged on to the computer.

The three types of programs are:-
-> A service Program
-> A service Control Program
-> A service Configuration Program.
What is Type Inferencing?

The Type Inferencing is a technique which is used to get the data type of the
variable that is determined by the compiler on the basis of the value assigned to the
variable.
The variable must be declared using the var keyword and shouldn't have
null values. The variable should also be assigned some value and the declaration
should be method level.

Like var value=100;
But we can't mention like var value=null;
Is it possible to get the Registry values through C#.net , if so what classes used for it?

With the help of Registry and RegistryKey classes of Microsoft.win32 we can do in .net.
We create instance of Registrykey class . Registry is static class , so we can access its method directly.
Sample in highlevel:

[code]RegistryKey Obj;
obj=Register.LocalMachine
Object Value=Obj.GetValue("Variable")[/code]
What is Jump Constructs?

The break statement causes an immediate exit from the for, switch, while statements.

example:

for(count=0;count<20;count++)

{
if(count==10)
{
break;
}
}

Can you declare the override method as static while the original method is non-static ?

No, you cannot, the signature of the virtual method must remain the same, only the keyword "virtual" is changed to keyword "override" .

//Base Class

Public Class BaseClass
{
public virtual string Name()
{
return "my name";
}
}


//Derived Class

Public Class DerivedClass: BaseClass
{
public override string Name()
{
return "my name is Akiii";
}
}




Thanks and Regards
Akiii
Why is the "new" keyword used for instantiating an object in .Net ?

The "new" keyword instructs the compiler to instantiate a new object, with appropriate number of bytes depending upon the type of the object and gather required memory from the heap.

Example:-

Classname objectname = new  Classname();




Thanks and Regards
Akiii
What is the purpose of x86, x64 and anycpu platform switch in C# compiler?

When you build any assembly in .Net environment that time you need to used any of these /platform switch or either in Visual Studio pick the platform value inside configuration manager settings.
/platform:x86 - x86 compiles your assembly to be run by the 32-bit, x86-compatible common language runtime.
/platform:anycpu - anycpu (default) compiles your assembly to run on any platform.
/platform:anycpu - x64 compiles your assembly to be run by the 64-bit common language runtime on a computer that supports the AMD64 or EM64T instruction set.
/platform:anycpu - Itanium compiles your assembly to be run by the 64-bit common language runtime on a computer with an Itanium processor.
How to sort array elements in descending order in C#?

int[] array = new int[] { 3, 1, 4, 5, 2 };


//Declare Array

Array.Sort<int>( array );

// Sort Method used Asending Order

Array.Reverse( array );

// reverse Method used Decenting Order

What are Declaration Statements ?

A Declaration Statement declares a Local Variable or Constant Variable .

These Statements are allowed in blocks but are not permitted as Embedded Statements.

Declaration can be done in this way :


declaration-statement:
local-variable-declaration ;
local-constant-declaration ;

What is Scavenging in .NET?

When we implement the Caching concept in the application,all the cached items will be stored in the memory.When executing the application if memory resources are low,then all the cached items stored in the memory get remove from the caching.this concept is called Scavenging .
How can we clear Cache stored in browser ?

Below mentioned code is useful to clear the Cache stored in the Browser.


Response.ExpiresAbsolute = DateTime.Now;
Response.Expires = -1441;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Pragma", "no-store");
Response.AddHeader("cache-control", "no-cache");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoServerCaching();


Note


This code is useful only when the caching is done in the server.
List<int> list = new List<int>(); list.Add(44); list.Add("mystring"); console.writeline(list); console.writeline(list);

NOTE: This is objective type question, Please click question title for correct answer.
Give brief description about Session Object ?


The Session object


. We can use the Session object to store information needed for a particular user-session.

. Variables stored in the Session object are not removed when the user navigates from one page to another instead, these variables sustain for entire user session.

. The Web Server creates a Session object automatically when a request from an user made even though he do not have a session.

. The server destroys the Session object when the session expires or is abandoned.

. One common use for the Session object is to store user preferences. For example, if a user indicates that they prefer not to view graphics, you could store that information in the Session object.
What are Value types and Reference types ?



.Value Types :
Value Types are those which directly have their data or allocated on the stack or using a specific structure.

.Reference Types :
Reference types are those which store a reference to a value's memory address which are allocated on the heap. These types can be pointer types,interface types or self describing.
When we have one single try statement and multiple catch blocks can these multiple catch blocks be executed ?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories