![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert.ChangeType Method in C#
The ChangeType() method returns an object of the specified type and whose value is equivalent to the specified object.
Let’s say we have a double type.
double val = -3.456
Now, use the ChangeType method to change the type to integer.
num = (int)Convert.ChangeType(val, TypeCode.Int32);
Let us see the complete example.
Example
using System; public class Demo { public static void Main() { double val = -3.456; int num = (int)Convert.ChangeType(val, TypeCode.Int32); Console.WriteLine("{0} converted to an Int32: {1}", val, num); } }
Output
-3.456 converted to an Int32: -3
Advertisements