Cant seem to transalte this VB code to C#

R

Ron Vecchi

The error Im getting--
The type or namespace name 't' could not be found (are you missing a using
directive or an assembly reference?)
The error is referencing the IF expression

VB.NET to convert
-----------------------------------------------
Public Overloads Overrides Function CanConvertFrom _
(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
If (TypeOf t Is String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, t)
End Function


C# That Im getting error on
-----------------------------------
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
{
if(typeof(t) is String){
return true;
}
return base.CanConvertFrom (context, t);
}
 
J

John Saunders

Ron Vecchi said:
The error Im getting--
The type or namespace name 't' could not be found (are you missing a using
directive or an assembly reference?)
The error is referencing the IF expression

VB.NET to convert
-----------------------------------------------
Public Overloads Overrides Function CanConvertFrom _
(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
If (TypeOf t Is String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, t)
End Function


C# That Im getting error on
-----------------------------------
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
{
if(typeof(t) is String){
return true;
}
return base.CanConvertFrom (context, t);
}

Try "if (t is string)".
 
J

Jacob Yang [MSFT]

Hi Ron,

Firstly I want to thank John for his great help in this issue.

Based on my research and experience, what you want should be something like
the following code snippet.
...
String test = "Hello";
Type t = test.GetType();
if ( t.ToString() == "System.String" )
{
TextBox1.Text = "Hello String";
}
...
Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top