converting this code form vb.net to C#

J

Jeff

Hi

..Net 3.5

Below is some vb.net code I'm trying to understand and convert to c#. Okay
the 2 first lines are okay. but the last 2 lines I have trouble with. For me
it looks like an if test,

TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()
Dim div As System.Web.UI.Control = Page.FindControl("divCalendar")

If TypeOf div Is HtmlGenericControl Then
CType(div, HtmlGenericControl).Style.Add("display", "none")
End If

----
I converted the if test to this:
if (typeof(div) == HtmlGenericControl)
{
}

not sure that is correct translation

and another thing that bugs my mind is that in the vb.net code AFAIK, the if
test if div is of type HtmlGenericControl. okay but the code inside the if
test tryes to covert to HtmlGenericControl. don't see how a covert is needed
there... I'm confused here

any suggestions?
 
B

bruce barker

vb is a typed language like c#. As div is declared as a Control (base
class), then if it is type HtmlGenericControl it can be cast as
HtmlGenericControl, to call methods/props.

the c# code is:

if (div is HtmlGenericControl)
{
((HtmlGenericControl) div).Style.Add("display", "none");
}


-- bruce (sqlwork.com)
 
D

David Anton

(See Bruce's answer)
The problem is keyword overlap - the same keywords (such as TypeOf/typeof)
have different meanings in VB and C#.
VB: C#:
TypeOf x Is Foo x is Foo
x Is Foo x == Foo
GetType(x) typeof(x)
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top