[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert C# to VB.Net

Posted on 2006-06-29
5
Medium Priority
?
496 Views
Last Modified: 2008-03-03
Can any one show me what this looks like in VB.NET

[Serializable]
public class MyObject : ISerializable
{
  public int n1;
  public int n2;
  public String str;

  public MyObject()
  {
  }

  protected MyObject(SerializationInfo info, StreamingContext context)
  {
    n1 = info.GetInt32("i");
    n2 = info.GetInt32("j");
    str = info.GetString("k");
  }
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter
=true)]
  public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
  {
    info.AddValue("i", n1);
    info.AddValue("j", n2);
    info.AddValue("k", str);
  }
}
0
Comment
Question by:ExtremeFitness
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17012857
I think it should be:

<Serializable()> _
Public Class MyObject
    Implements ISerializable

    Public n1 As Integer
    Public n2 As Integer
    Public str As String

    Public Sub New()

    End Sub

    Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        n1 = info.GetInt32("i")
        n2 = info.GetInt32("j")
        str = info.GetString("k")
    End Sub

    <SecurityPermission(SecurityAction.Demand, SerializationFormatter:=True)> _
    Public Overridable Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
        info.AddValue("i", n1)
        info.AddValue("j", n2)
        info.AddValue("k", str)
    End Sub

End Class
0
 
LVL 1

Expert Comment

by:norberg01
ID: 17014536
Hi,
the previous comment is the right answer to your question.
But if you want to convert code quickly, you can try this web site :
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

The result is not always accurate, but it does almost the right conversion for you.

Hope it helps

Patrice
0
 
LVL 2

Accepted Solution

by:
Mystify earned 1500 total points
ID: 17156747
book moark these sites, it's what I use:

http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

Some work better than others depending on the code itself, but using them I can usually get it working.


This is what I got:

<Serializable()>  _
Public Class MyObject
    Inherits ISerializable
   
    Public n1 As Integer
    Public n2 As Integer
    Public str As String
   
    Public Sub New()
        MyBase.New
    End Sub
   
    Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        MyBase.New
        n1 = info.GetInt32("i")
        n2 = info.GetInt32("j")
        str = info.GetString("k")
    End Sub
   
    <SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter:=true)>  _
    Public Overridable Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        info.AddValue("i", n1)
        info.AddValue("j", n2)
        info.AddValue("k", str)
    End Sub
End Class
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question