473,769 Members | 5,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatic type casting?

How does automatic type casting happen in vb.net? I notice that
databinder.eval "uses reflectoin" to find out the type it's dealing with.
Does vb.net do the same thing behind the scenes when an invisible cast is
made? Is there any reason why one would use databinder.eval while in VB.NET?
I can see why one might use it in C# so as to avoid specifying the type for
the cast but since this is not necessary in VB.NET, I'm not sure I follow.

Thanks...

-Ben
Feb 6 '06 #1
7 4222
Hi Ben,

It is different thing for type casting in databinder.eval and in VB.NET
language. Yes, as you can see the databinder.eval uses reflection to do
the casting. While the VB.NET language automatically cast is a technique
inside the VB.NET compiler, which is build-in for the language.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 6 '06 #2
Hi Kevin,

Not sure I follow. If the vb.net conversion is a compile time conversion,
how is it possible to, in vb.net, omit the databinder.eval and simply use
container.datai tem without a cast? At compile time, how would it make a
casting decision?

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

It is different thing for type casting in databinder.eval and in VB.NET
language. Yes, as you can see the databinder.eval uses reflection to do
the casting. While the VB.NET language automatically cast is a technique
inside the VB.NET compiler, which is build-in for the language.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 6 '06 #3
Hi Ben,

The databinder.eval is required in data binding and cannot be omitted
despite the language change. The compile time type casting is build-in in
the compiler and we have no idea of how it was implemented.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 7 '06 #4
Hi Kevin,

I'm not sure this is the case. In my ASP.NET (VB.NET) pages, I have code
such as the following:

<ItemTemplate >
<tr>
<td>
<asp:Label ID="themessage " runat="server" Text='<%#
Container.Datai tem("MsgSubject ") %>' /></td>
</tr>
</ItemTemplate>
or

<td>
<%# Container.Datai tem("RunDistanc e")%>
</td>

Note the absence of Databinder.Eval . This is running on ASP.NET 2.0 without
a problem. It also ran on 1.1 without a problem.

I was under the impression that this could only be the case on VB.NET and
not C#. Could you clarify your last post please?

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

The databinder.eval is required in data binding and cannot be omitted
despite the language change. The compile time type casting is build-in in
the compiler and we have no idea of how it was implemented.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 7 '06 #5
Hi Ben,

The Eval method returns a string from the source column, which is the best
way to use databinding in ASP.NET. However, this can run without problem
because of the VB's automatic data type convertion, Actually, it's also
getting a string from the column. It's better to use Eval here for
compatibility issue. You can check for a best practice in the following
link:

http://msdn2.microsoft.com/en-us/library/ms178366.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 8 '06 #6
Hi Kevin,
The Eval method returns a string from the source column, which is the best
way to use databinding in ASP.NET. However, this can run without problem
because of the VB's automatic data type convertion,
This isn't exactly' whawt I meant. I was referring to omitting the eval
method entirely, which also works. You were saying that this can run without
a problem because of VB.NET's automatic type conversion. is this the compile
time conversion you mentioned? Or is this late binding? And in either case,
why would one ever use datavinder.eval then? To demonstrate, i created a
simple webpage:
<%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Defau lt.aspx.vb"
Inherits="_Defa ult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate >
<%# Container.Datai tem %>
</ItemTemplate>

</asp:DataList>
</div>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.P age

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim myarray() As Integer = {2, 4, 5, 3}
DataList1.DataS ource = myarray
DataList1.DataB ind()
End Sub
End Class

This runs without problems. Notice that it's pulling an integer and not a
string, and yet the output is correct. So does VB.NET provide late binding
behind the scenes? Or just compile time conversion? And if only compile time,
how am I not seeing an exception?

-Ben
"Kevin Yu [MSFT]" wrote:
Hi Ben,

The Eval method returns a string from the source column, which is the best
way to use databinding in ASP.NET. However, this can run without problem
because of the VB's automatic data type convertion, Actually, it's also
getting a string from the column. It's better to use Eval here for
compatibility issue. You can check for a best practice in the following
link:

http://msdn2.microsoft.com/en-us/library/ms178366.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 8 '06 #7
Hi

Based on my test, the code below works in a C# 2.0 asp.net page.
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
int[] Nums= new int [5]{1,2,3,4,5};
DataList1.DataS ource = Nums;
DataList1.DataB ind();
}
}

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate >
<%# Container.DataI tem %>
</ItemTemplate>
</asp:DataList></div>
</form>
</body>
</html>

I think this is a binding issue. The DataBinding mechanism will help to
call the Int.ToString() on the integer to format it as a string.
This is not a language feature. but a databinding desing.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 9 '06 #8

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

Similar topics

5
8269
by: Suzanne Vogel | last post by:
** Isn't the 'static_cast' operator the same as traditional type casting? ie, Aren't the following ways of getting b1, b2 the same? // 'Derived' is derived from 'Base' Derived* d = new Derived(); Base* b1 = static_cast<Base*>(d); Base* b2 = (Base*)d; // traditional type casting Such is my understanding from code samples, my own uses, and this: http://www.cplusplus.com/doc/tutorial/tut5-4.html
4
3481
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A good way to do this is by example. So I will give an example and please tell me what you think: I have a base class A with a virtual destructor, and a class B that is it inherits publicly from A and defines som extra stuff.
6
19212
by: Jim Bancroft | last post by:
Hi everyone, I'm having some trouble with the code below. I receive a compile-time error on the second line saying "; expected": private static void myTestFunction(long myLong) { System.Data.SqlTypes.SqlInt32 myTestInt;
10
11800
by: Bob | last post by:
This has been bugging me for a while now. GetType isn't availble for variables decalred as interface types, I have to DirectCast(somevariable, Object). In example: Sub SomeSub(ByVal Dictionary as IDictionary) If Dictionary is Nothing Then Return Dim o as Object = DirectCast(Dictionary, Object)
23
3523
by: René Nordby | last post by:
Hi there, Is there anyone that knows how to do the following? I have a class A and a class B, that 100% inherits from class A (this means that I don't have other code in class B, than the Inherit statement).
6
2524
by: crook | last post by:
I have code below and it works properly but when I'm compiling it with "--pedantic" flag, GCC(3.4.2) shows such warning: "ISO C forbids casting nonscalar to the same type". How can I change this code to get rid of this warning? /*parameters is void* type*/ struct params p = ( struct params )*( ( struct params * )parameters );
15
7626
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
4
4829
by: beena | last post by:
All, I'm new to the concept of automatic storage... I'm looking at the database setup by a vendor. I see few tablespaces showing up with automatic storage - Yes. Tablespace ID = 0 Name = SYSCATSPACE Type = Database managed space Tablespace ID = 1 Name = TEMPSPACE1
2
3334
by: bryars | last post by:
I want to write some SQL which results in an automatic conversion of a datetime to a string in a format suitable for the Language of the connection (either by explicitly setting the Language in the connection string, or by setting the default language in for the user used for the connection.) The casting from string to datetime uses the language setting: Data Source=localhost\sqlexpress;Initial Catalog=master;Persist Security...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.