473,289 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Why do ASP.NET Settings Properties use CTYPE instead of DirectCast

If Visual Studio knows the type, why does the system-generated property use
CType instead of DirectCast? DirectCast is more efficient right?

For example - Here's what we have for a setting named
'StandardWebsiteUserRoleID'...
Public ReadOnly Property StandardWebsiteUserRoleID() As Integer
Get
Return CType(Me("StandardWebsiteUserRoleID"),Integer)
End Get
End Property

Thanks
Sep 3 '07 #1
3 2173
I think CType is a VB wrapper for DirectCast, and as such, it probably has
some additional checks that DirectCast doesn't have.

Mike Ober.

"Mike" <Mi**@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.com...
If Visual Studio knows the type, why does the system-generated property
use
CType instead of DirectCast? DirectCast is more efficient right?

For example - Here's what we have for a setting named
'StandardWebsiteUserRoleID'...
Public ReadOnly Property StandardWebsiteUserRoleID() As Integer
Get
Return CType(Me("StandardWebsiteUserRoleID"),Integer)
End Get
End Property

Thanks


Sep 4 '07 #2
Ctype doesn't throw an exception, DirectCast, while more efficient, assumes
that you know exactly what the type is. Additional behavior would be
controlled by having Option Strict and Option Explicit both set to "true" -
which you should always do with VB.NET.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mike" wrote:
If Visual Studio knows the type, why does the system-generated property use
CType instead of DirectCast? DirectCast is more efficient right?

For example - Here's what we have for a setting named
'StandardWebsiteUserRoleID'...
Public ReadOnly Property StandardWebsiteUserRoleID() As Integer
Get
Return CType(Me("StandardWebsiteUserRoleID"),Integer)
End Get
End Property

Thanks
Sep 4 '07 #3
Your statement is exactly correct. So then why for Settings, when we do know
exactly what the type is, doesn't Visual Studio use DirectCast instead of
CTYPE?

It just seems logical to me that since we're sure of the type, Visual Studio
chooses to use CTYPE.

In the end it doesn't really matter, but it does make me curious.

"Peter Bromberg [C# MVP]" wrote:
Ctype doesn't throw an exception, DirectCast, while more efficient, assumes
that you know exactly what the type is. Additional behavior would be
controlled by having Option Strict and Option Explicit both set to "true" -
which you should always do with VB.NET.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mike" wrote:
If Visual Studio knows the type, why does the system-generated property use
CType instead of DirectCast? DirectCast is more efficient right?

For example - Here's what we have for a setting named
'StandardWebsiteUserRoleID'...
Public ReadOnly Property StandardWebsiteUserRoleID() As Integer
Get
Return CType(Me("StandardWebsiteUserRoleID"),Integer)
End Get
End Property

Thanks
Sep 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joeri | last post by:
Hi, I'm struggling with this issue, maybe someone has already solved ik before. Here's the problem I Have : clsA witch is a base class clsB inherits from clsA clsC inherits from clsA clsD...
13
by: Carl Howarth | last post by:
Hello there, I am currently in the process of 'getting strict' with some of our aspx.vb files. I have a function that is called either when a datarepeater is bound or when a button on the...
4
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
6
by: Ot | last post by:
I apparently have a bit to learn about Casting and Conversion. I have been thinking of them as the same but a discussion in another thread leads me to believe that this is wrong thinking. I...
8
by: John A Grandy | last post by:
could someone please discuss the pros and cons of CType(MyDouble,Decimal) versus Convert.ToDecimal(MyDouble) .... and other such conversions ...
7
by: Brian Henry | last post by:
is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one take up more cycles then the other? thanks
5
by: Matt | last post by:
Does anyone know or care to find out the speed difference between a directcast call and a direct call? for instance, i might have these lines of code: dim j as collections.arraylist ...
5
by: Rich | last post by:
In VB6 I used to be able to add an object like a textbox and see the dropdown properties of that textbox from the collection object: Dim col as collection set col = new collection col.Add(txt1)...
5
by: Andy | last post by:
I need to write a VB.NET WinForms app. For this purpose I need to keep some settings of the application, like many other Windows applications do. The most obvious solution is to store settings in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.