Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you translate this from VB.NET to C#.NET??? 1

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
How do you translate this from VB.NET TO C#.NET

Code:
    Private ReadOnly c_bKey() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
    Private ReadOnly c_bIv() As Byte = {8, 7, 6, 5, 4, 3, 2, 1}

Thanks...
 
byte[] c_bKey = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
byte[] c_bIv = new byte[] {8, 7, 6, 5, 4, 3, 2, 1};

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
By the way.. There are online/desktop utilities available for the translation.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Ah! The Byte and byte are two different things... Gotcha!

I'm still getting a compile error, so I'll just post the whole thing here to see if anyone can help me out... The compiler error kept complaining about "this.c_bKey[]" & "this.c_bIv[]"... I post a seperate code for the foo class.

//This code...
Code:
private byte[] c_bKey = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
private byte[] c_bIv = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
private EncryptionType c_oEncryption = new EncryptionType(this.c_bKey[], this.c_bIv[]);

//Class...
Code:
public class EncryptionType_TripleDES
{
    //Constructor...
    public EncryptionType_TripleDES(byte[] key, byte[] iv)
    {
        this.c_key = key;
        this.c_iv = iv;
    }
}

Thanks...
 
Since I can't edit the post, so here's the correction for the foo function...

Code:
public class EncryptionType_TripleDES
{
    //define the local property arrays
    private byte[] c_key;
    private byte[] c_iv;

    //Constructor...
    public EncryptionType_TripleDES(byte[] key, byte[] iv)
    {
        this.c_key = key;
        this.c_iv = iv;
    }
}
 
this line is the problem
private EncryptionType c_oEncryption = new EncryptionType(this.c_bKey[], this.c_bIv[]);
varible[] is invalid syntanx. it also doesn't work to initialize in the field, because the arrays are initialized there as well.

move this to ctor and you'll be fine
Code:
public class Foo
{
   private byte[] c_bKey = new byte[] { ... };
   private byte[] c_bIv = new byte[] { ... };
   private readonly EncryptionType c_oEncryption;
   
   public Foo()
   {
      c_oEncryption = new EncryptionType(c_bKey, c_bIv);
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I'm still getting the compiler error, it's a different one now...

It said "A field initializer cannot reference the non-static field, method, or property 'signin.c_bKey'"....

The "EncryptionType_TripleDES" is a class with it's own constructor but not the other sample code I posted cuz it's on an ASP.NET webpage... The "sigin" is the name of the class on the ASP.NET webpage...
 
Got it! Putting this "c_oEncryption = new EncryptionType(c_bKey, c_bIv);" into the Page_Load function does the trick.

Now I'm beginning to understand why I got this error. If you step through a call to a constructor of a class, you will see that all member variables are initialized before the constructor is invoked. So, trying to initialize this "blah = new EntryptionType(c_bKey, c_bIv);"

Invoked a property of the class, but the instance was still under construction, and so unable to return a value from that property.

 
Yup. Static variables get initialized first (as you'd expect, since they're shared amongst all instances), and then the instance variables get initialized, and then one of the constructors gets called.

Chip H.


____________________________________________________________________
www.chipholland.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top