Solved

Convert C# to VB.Net

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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