Converting C# to Vb.net 2003

DekaFlash

Well-known member
Joined
Feb 14, 2006
Messages
117
Programming Experience
1-3
Is thie code below a good equivalent of the C# version, which I have included at the bottom.

VB Version

Public Shared Function GetStaleSessionTokens(ByVal staleAge As TimeSpan) As IList
Dim staleSessions As IList = New ArrayList()
SyncLock m_sessionTokens.SyncRoot
Dim allSessions As Queue = CType(m_sessionTokens.Clone(), Queue)
m_sessionTokens.Clear()

For Each session As TimestampedSession In allSessions
If session Is Nothing Then
GoTo Continue1
End If

If session.Timestamp.Compare(session.Timestamp, DateTime.Now.Subtract(staleAge)) Then
m_sessionTokens.Enqueue(session)
Else
staleSessions.Add(session.SessionToken)
End If

Continue1:
Next session
End SyncLock
Return staleSessions
End Function

C# Version

public static IList GetStaleSessionTokens(TimeSpan staleAge)
{
IList staleSessions = new ArrayList();
lock (m_sessionTokens.SyncRoot)
{
Queue allSessions = (Queue)m_sessionTokens.Clone();
m_sessionTokens.Clear();

foreach (TimestampedSession session in allSessions)
{
if (session == null) continue;

if (DateTime.Now.Subtract(session.Timestamp) > staleAge)
{
staleSessions.Add(session.SessionToken);
}
else
{
m_sessionTokens.Enqueue(session);
}
}
}
return staleSessions;
}
 
Last edited:
Is thie code below a good equivalent of the C# version, which I have included at the bottom.

VB Version

Public Shared Function GetStaleSessionTokens(ByVal staleAge As TimeSpan) As IList​
Dim staleSessions As IList = New ArrayList()​
SyncLock m_sessionTokens.SyncRoot
Dim allSessions As Queue = CType(m_sessionTokens.Clone(), Queue)​
m_sessionTokens.Clear()​
For Each session As TimestampedSession In allSessions​
If session Is Nothing Then​
GoTo Continue1
End If​
If session.Timestamp.Compare(session.Timestamp, DateTime.Now.Subtract(staleAge)) Then​
m_sessionTokens.Enqueue(session)
Else
staleSessions.Add(session.SessionToken)
End If
Continue1:​
Next session​
End SyncLock
Return staleSessions​
End Function​

C# Version​
 
Last edited:
I should also have mentioned that the WYSIWYG editor can break code a lot.

Ensure you press the
switchmode.gif

button before you post code, to switch to basic mode (bright white editor)

Now post your indented code and the indent are preserved

Alternataly, paste your code into notepad first, then cut it out and paste it in here
 
Do not use GoTo

VB.NET supports Continue just like C#; type it and the IDE will add any additional syntax needed (e.g. Continue For)
 
Back
Top