Converting C# to VB

B

Bob Roy

Could someone help me translating the following C# code to VB? Is there
a different newsgroup where it would be better to post this?

[ListBindable(false)]
public class CategoriesInfo : CollectionBase {
static CategoriesInfo instance;
// create the static instance of the class
static CategoriesInfo() {
instance = new CategoriesInfo();
}
public CategoryInfo this[int index] { get { return List[index] as
CategoryInfo; } }
public CategoryInfo this[string name] {
get {
for(int i = 0; i < Count; i ++)
if(name.ToUpper() == this.Name.ToUpper())
return this;
return null;
}
}

// Register the category in the system
public static void Add(string name, int imageIndex) {
CategoryInfo item = new CategoryInfo(name, imageIndex);
instance.List.Add(item);
}
public static void Add(string name) {
CategoriesInfo.Add(name, -1);
}
public static CategoriesInfo Instance { get { return instance; } }
}
 
A

Anibal

<ListBindable(False)> _
Public Class CategoriesInfo
Inherits CollectionBase
Shared m_instance As CategoriesInfo
' create the static instance of the class
Private Shared Sub New()
m_instance = New CategoriesInfo()
End Sub
Public Default ReadOnly Property ConvertedIndexer(ByVal index As Integer) As
CategoryInfo
Get
Return TryCast(List(index), CategoryInfo)
End Get
End Property
Public Default ReadOnly Property ConvertedIndexer(ByVal name As String) As
CategoryInfo
Get
For i As Integer = 0 To Count - 1
If name.ToUpper() = Me(i).Name.ToUpper() Then
Return Me(i)
End If
Next
Return Nothing
End Get
End Property
' Register the category in the system
Public Shared Sub Add(ByVal name As String, ByVal imageIndex As Integer)
Dim item As CategoryInfo = New CategoryInfo(name, imageIndex)
m_instance.List.Add(item)
End Sub
Public Shared Sub Add(ByVal name As String)
CategoriesInfo.Add(name, - 1)
End Sub
Public Shared ReadOnly Property Instance() As CategoriesInfo
Get
Return m_instance
End Get
End Property
End Class
 
G

Guest

The other post was mostly correct, but there were two mistakes: 1. the
constructor is not private and 2. the indexers should be named the standard
"Item".
Our Instant VB C# to VB converter produces:
<ListBindable(False)> _
Public Class CategoriesInfo : Inherits CollectionBase
Private Shared instance_Renamed As CategoriesInfo
' create the static instance of the class
Shared Sub New()
instance_Renamed = New CategoriesInfo()
End Sub
Public ReadOnly Default Property Item(ByVal index As Integer) As
CategoryInfo
Get
Return TryCast(List(index), CategoryInfo)
End Get
End Property
Public ReadOnly Default Property Item(ByVal name As String) As CategoryInfo
Get
For i As Integer = 0 To Count - 1
If name.ToUpper() = Me(i).Name.ToUpper() Then
Return Me(i)
End If
Next i
Return Nothing
End Get
End Property

' Register the category in the system
Public Shared Sub Add(ByVal name As String, ByVal imageIndex As Integer)
Dim item As CategoryInfo = New CategoryInfo(name, imageIndex)
instance_Renamed.List.Add(item)
End Sub
Public Shared Sub Add(ByVal name As String)
CategoriesInfo.Add(name, -1)
End Sub
Public Shared ReadOnly Property Instance() As CategoriesInfo
Get
Return instance_Renamed
End Get
End Property
End Class

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
G

Guest

If you tried the original poster's C# code in any of those converters (I just
did), you'd see that the output is unacceptable non-compilable code.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



chanmm said:
Convert your code here:
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
http://www.ragingsmurf.com/vbcsharpconverter.aspx
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

Have fun!!!
chanmm


Bob Roy said:
Could someone help me translating the following C# code to VB? Is there
a different newsgroup where it would be better to post this?

[ListBindable(false)]
public class CategoriesInfo : CollectionBase {
static CategoriesInfo instance;
// create the static instance of the class
static CategoriesInfo() {
instance = new CategoriesInfo();
}
public CategoryInfo this[int index] { get { return List[index] as
CategoryInfo; } }
public CategoryInfo this[string name] {
get {
for(int i = 0; i < Count; i ++)
if(name.ToUpper() == this.Name.ToUpper())
return this;
return null;
}
}

// Register the category in the system
public static void Add(string name, int imageIndex) {
CategoryInfo item = new CategoryInfo(name, imageIndex);
instance.List.Add(item);
}
public static void Add(string name) {
CategoriesInfo.Add(name, -1);
}
public static CategoriesInfo Instance { get { return instance; } }
}

 

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

Top