Abstract class / method , how to C# --> VB.NET

2020-07-08 06:51发布

问题:

I am more familiar with VB and the book i bought has C# examples, now i am stuck.

How do I implement the following in VB.NET?

public abstract class ENTBaseDATA<T> where T : IENTBaseEntity

{
  public abstract List<T> Select();
  public abstract T Select(int id);

  etc....This code already is converted :)

}

For complete code see Chapter 2 download:

http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470396865,descCd-DOWNLOAD.html

回答1:

You could try to use a C# / VB.NET converter. Output:

Public MustInherit Class ENTBaseDATA(Of T As IENTBaseEntity)
    Public MustOverride Function [Select]() As List(Of T)
    Public MustOverride Function [Select](ByVal id As Integer) As T
    ' and then the other code '
End Class


回答2:

You should know:

Abstract Class:

In C#: abstract keyword

In VB.NET: MustInherit keyword

Abstract Method:

In C#: abstract keyword

In VB.NET: MustOverride keyword

Generic class or method:

In C#: Class<T> where T : Conditions

In VB.NET: Class(Of T As Conditions)

Finally, in VB.NET the word Select is a reserved keyword, so you have to enclose it between [ ] in order to use it.



回答3:

You can check some auto-converter, fe. http://www.kamalpatel.net/ConvertCSharp2VB.aspx. If it won't work, you can: create an assembly in c# (just compile your code), download .NET Reflector (if you don't have one! :) ), decompile assembly and convert it to VB.NET

//Edit removed code, as it seems it's broken (eh, those converters ;) ).