Cant seem to transalte this VB code to C#

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
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);
}
 
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)".
 
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.
 
Back
Top