Solved

Convert C# to VB.Net

Posted on 2006-06-29
5
489 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
5 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 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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:…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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