converting this code form vb.net to C#

  • Thread starter Thread starter Jeff
  • Start date Start date
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?
 
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)
 
(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++
 
Back
Top