crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Main difference between DirectCast and CType?
Question Posted on 19 Nov 2021Home >> DotNet >> ASP.NET >> Main difference between DirectCast and CType?

Main difference between DirectCast and CType?
Below are the main difference between DirectCast and CType
0
0

Base of differenceDirectCastCType
TypesWe generally used Directcast to cast reference types.We generally used Ctype to cast value types.
PortabilityDirectCast is portable across many languages as it is not very specific to VB.NET.On the other hand Ctype is specific to VB.NET and it is not portable.
PerformancePerformance of DirectCast is far better than ctype.Performance wise ctype is slow when compared to DirectCast.
RoutinesAs performance is better because no runtime helper routines of VB.NET are used for casting.As we are aware performamce is slower this is because ctype casting requires execution of runtime helper routines of VB.NET.
ExceptionIf we perform DirectCast on arguments if that don't match then it will throw InvalidCastException.Here exceptions are not thrown while using ctype.
ConversionIf we use DirectCast we cannot convert object of one type into another. Type of the object at runtime should be same as the type that is specified in DirectCast. Below is the example:- Dim sampleNumber as Integer Dim sampleString as String sampleNumber=400 sampleString=DirectCast(sampleNumber,String) Here above code will not work because runtime type of sampleNumber is Integer which is different from the specified type String.In Ctype cast of object of one type into another if the conversion is valid. Below is the example:- Dim sampleNumber as Integer Dim sampleString as String sampleNumber=400 sampleString=CType(sampleNumber,String) This code is legal and the Integer 100 is now converted to a string.


.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Use of Calendar control in dotnet with code

How to improve Front End UI performance of dotnet web application?

File upload in dotnet

reverse a string

function of garbage collector






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap