.Net Interview Questions and Answers

Search:

Explain the implicit and explicit conversion of data types with examples?( .NET interview questions on data type)

By : Shiv Prasad Koirala | Dec 21st, 2013 | Views : 2007 | Comments : 0 Bookmark and Share

To understand implicit and explicit conversion of data types first let's try to understand type casting concept. Type casting is a mechanism where we convert one type of data to other type.


For example below is simple code where we want to move integer (value without decimals) value to a double ( value with decimals). When we try to move double data type to integer data type casting occurs. Casting is also termed as conversion.


int i = 100;

double d = 0;

d = i; // casting


In the above example there is no loss of data. In other words when we moved 100 integer value to double we get the 100 value as it. This is termed as implicit conversion / casting.


Now consider the below code where we are trying to move a double to an integer. In this scenario in integer only 100 will be received decimals will be removed. You can also see I need to explicitly specify that we need to convert in to integer. This is termed as explicit conversion.


double d = 100.23;

int i = 0;

i = (int) d; // this will have 100, 0.23 will truncated.


This question is taken from the famous .NET interview question book by Bpb publication read more about the book from here http://www.flipkart.com/net-interview-questions-6th/p/itmdyuqzdqx8cvqx


Below is a nice video created by www.questpond.com which demonstrates type safety , casting , implicit casting and explicit casting.


 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

WCF Interview questions and answers: -What is the difference between WCF fault exceptions and normal .NET exceptions?

In this article we will show difference between WCF fault exceptions and normal .NET exceptions. For more articles and videos visit us on http://www.questpond.com/... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

MVC vs ASP.NET ( MVC Interview question with answers )?

In this article we will explain MVC vs ASP.NET.For more articles and videos visit us on www.questpond.com... Read More

C# and .NET interview question: - Define Named and Optional Arguments?

Visual C# 2010 introduces two interesting features called as Named and Optional Arguments.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

WCF Interview questions and answers: -What is the difference between WCF fault exceptions and normal .NET exceptions?

In this article we will show difference between WCF fault exceptions and normal .NET exceptions. For more articles and videos visit us on http://www.questpond.com/... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

MVC vs ASP.NET ( MVC Interview question with answers )?

In this article we will explain MVC vs ASP.NET.For more articles and videos visit us on www.questpond.com... Read More

C# and .NET interview question: - Define Named and Optional Arguments?

Visual C# 2010 introduces two interesting features called as Named and Optional Arguments.... Read More

Article Categories

Learn in Hindi