Visual Studio Interview Questions and Answers (81) - Page 1

What is BrowserLink ?

It is new feature introduced in VS 2013 which creates a communication channel(using ASP.Net SignalR) between the VS IDE (development environment) and one or more web browsers.

It allows you to refresh your web application in several browsers at once, which is useful for cross-browser testing means you can dynamic exchange data between your web application and Visual Studio.
How to raise Button Event?

We have button' ONCLICK event,by which we can raise or fire button event on windows application or web application.

For Example:-
<asp:Button ID="Button1" runat="server" Text="Button" OnClick = "Button1_Click"/>



protected void Button1_Click(object sender, EventArgs e)
{
//write your code
}

How to check whether any string has a value or not?

String data type has IsNullOrEmpty static function which is used for checking whether string conains any value or not.
Syntax:-
string.IsNullOrEmpty(string value);

How to define Enum in .Net?

In C#,
public enum Active_Inactive

{
Active = 0,
Inactive = 1
}

In VB.Net
 Public Enum Active_Inactive

Active = 0
Inactive = 1
End Enum

How to get an Enum member given its integer value.

'VB.Net
Dim enum_obj As Active_Inactive

Dim value As Integer = 1
enum_obj = CType(value,Active_Inactive)
MasBox(enum_obj.ToString())

//C#
Active_Inactive enum_obj;

int value = 1;
enum_obj = (Active_Inactive)value;
MessageBox.Show(enum_obj.ToString());

How to retrieve an Enum member by their Name?

To retrieve an Enum member given by their Name,we will use the ConvertFrom() method of the TypeConverter class and cast the result to our Enum type as

'VB.Net
enum_obj = CType(System.ComponentModel.TypeDescriptor.GetConverter(enum_obj).ConvertFrom("Active"),Active_Inactive)

MasBox(enum_obj.ToString())

//C#
enum_obj = (Active_Inactive)TypeDescriptor.GetConverter(enum_obj).ConvertFrom("Active");

MessageBox.Show(enum_obj.ToString());

What is an Alternative way to retrieve an Enum member by their Name?

VB.Net
enum_obj = CType(System.Enum.Parse(GetType(Active_Inactive), "Active"),Active_Inactive)

C#
enum_obj = (Active_Inactive)Enum.Parse(typeof(Active_Inactive), "Active");

How to fetch an Enum value directly by its Values?

We can directly write Enum_Name.Value as shown below:-
MessageBox.Show(Active_Inactive.Active);

MessageBox.Show(Active_Inactive.Inactive);

How to retrieve Enum value using its GetValues method?

As name suggests,GetValues method have array values.So we can Loop through Enum Values as:-

//C#
foreach(int value in Enum.GetValues(typeof(Active_Inactive)))
{
MessageBox.Show(value);
}
'VB.Net
For Each value In [Enum].GetValues(GetType(Active_Inactive))
MessageBox.Show(value)
Next

How to retrieve Enum value using its GETNAME Method?

GetName is a static method,so we can directly access this by Enum_Name.GetName as shown below:-
MsgBox([Enum].GetName(GetType(Active_Inactive),1)) //Where 1 is an Index Position of Enum Values

Output:-
Active

MessageBox.Show(Enum.GetName(typeof(Active_Inactive),2));

Output:-
Inactive

How to retrieve Enum values using its GETNAMES Method?

As with GETVALUES Method,we can also retrieve the same thing using GETNAMES method.Here,we also have to Loop through Enum values:-
For Each value In [Enum].GetNames(GetType(Active_Inactive))

MessageBox.Show(value)
Next

foreach(string value in Enum.GetNames(typeof(Active_Inactive)))
{
MessageBox.Show(value);
}

Output:-
Active
Inactive

What's difference between Enum.GetValues and Enum.GetNames method?

GetValues method will return an Array of the underlying values for each item in the Enum.
Whereas GetNames method will return a string array of the Names for the items in the enum.
What's difference between VB.Net Enum and C# Enum?

Both declaration is same but only one difference is that,in VB.Net,we do not use COMMA(,) inside ENUM but in case of C#,we provide COMMA(,) in between values.
For Example:-
public enum DateFormatStyle 

{
Rounded,
Truncated
};

Public Enum DateFormatStyle
Rounded
Truncated
End Enum

Which method of file class is used to check whether file is present or not?

NOTE: This is objective type question, Please click question title for correct answer.
How to get File Attributes?

We can use System.IO.File class GetAttributes static method to get the file attributes.

For Example:-
FileAttributes fa = System.IO.File.GetAttributes("file_name_path");

It has enum values like Hidden,Readonly and so on.
Which Enum value is used to set Attributes as Hidden to a File?

NOTE: This is objective type question, Please click question title for correct answer.
Which Enum value is used to clear or reset any file attributes?

NOTE: This is objective type question, Please click question title for correct answer.
Which Enum value is used to set Readonly attributes to any file?

NOTE: This is objective type question, Please click question title for correct answer.
How to check whether a file has a ReadOnly Attribute or not?

We will write below code to check whether a file has a ReadOnly Attribute or not:-
if(((File.GetAttributes("file_path") & FileAttributes.ReadOnly) == FileAttributes.ReadOnly))

{
return true;
}
return false;

How to check whether a file has a Hidden Attribute or not?

We will write below code to check whether a file has a Hidden Attribute or not:-

if(((File.GetAttributes(filePath) & FileAttributes.Hidden) == FileAttributes.Hidden))

{
return true;
}
return false;

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