如何把这VB代码转为C#?
Public Function Encode(ByVal S As String) As String 
On Error GoTo acd
    If Len(S) = 0 Then Exit Function
    Dim Buff() As Byte
    Buff = StrConv(S, vbFromUnicode)
    Dim i As Long
    Dim j As Byte
    Dim k As Byte, m As Byte
    Dim mstr As String
    mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
    Dim outs As String
    i = UBound(Buff) + 1
    outs = Space(2 * i)
    Dim Temps As String
    For i = 0 To UBound(Buff)
        Randomize Time
        j = CByte(5 * (Math.Rnd()) + 0) '最大产生的随机数只能是5,不能再大了,再大的话,就要多用一个字节
        Buff(i) = Buff(i) Xor j
        k = Buff(i) Mod Len(mstr)
        m = Buff(i) \ Len(mstr)
        m = m * 2 ^ 3 + j
        Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
        Mid(outs, 2 * i + 1, 2) = Temps
     Next
     Encode = outs
Exit Function
acd:
End FunctionPublic Function Decode(ByVal S As String) As String 
    On Error GoTo acd
    Dim i As Long
    Dim j As Byte
    Dim k As Byte
    Dim m As Byte
    Dim mstr As String
    mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
    Dim t1 As String, t2 As String
    Dim Buff() As Byte
    Dim n As Long
    n = 0
    For i = 1 To Len(S) Step 2
        t1 = Mid(S, i, 1)
        t2 = Mid(S, i + 1, 1)
        k = InStr(1, mstr, t1) - 1
        m = InStr(1, mstr, t2) - 1
        j = m \ 2 ^ 3
        m = m - j * 2 ^ 3
        ReDim Preserve Buff(n)
        Buff(n) = j * Len(mstr) + k
        Buff(n) = Buff(n) Xor m
        n = n + 1
     Next
     Decode = StrConv(Buff, vbUnicode)
     Exit Function
acd:
     Decode = ""
End Function谢了

解决方案 »

  1.   

    你可以在这个页面做VB.NET->C#的转换:
    http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
      

  2.   

    但vb->vb.net我也不会啊
    高手们
      

  3.   

    晕,别谈分啦,志在互相帮助,我从来不注重这CDSN的分数,
    刚才问了一下,有人说我给我分数少(论坛默认的20分)
    现在再开一贴,特意加到100分(不够再说吧)
    还是有人说分数少那我把我所有的分数全给了,行不行?
      

  4.   

    刚才用一个工具转换,不知对不对,结果如下:
    public string Encode(string S) {
            // TODO: On Error GoTo Warning!!!: The statement is not translatable 
            if ((S.Length == 0)) {
                // TODO: Exit Function: Warning!!! Need to return the value
            }
            return;
            byte[] Buff;
            Buff = StrConv(S, vbFromUnicode);
            long i;
            byte j;
            byte k;
            byte m;
            string mstr;
            mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
            string outs;
            i = (UBound(Buff) + 1);
            outs = Space((2 * i));
            string Temps;
            for (i = 0; (i <= UBound(Buff)); i++) {
                Randomize;
                Time;
                j = byte.Parse(((5 * Math.Rnd()) 
                                + 0));
                Buff[i] = Buff[i];
                j;
                k = (Buff[i] % mstr.Length);
                m = Buff[i];
                mstr.Length;
                m = ((m * 2) | (3 + j));
                // TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
                Temps = (mstr.Substring(k, 1) + mstr.Substring(m, 1));
                outs.Substring((2 * i), 2) = Temps;
            }
            return outs;
            
        acd:
        }
        
        public string Decode(string S) {
            // TODO: On Error GoTo Warning!!!: The statement is not translatable 
            long i;
            byte j;
            byte k;
            byte m;
            string mstr;
            mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
            string t1;
            string t2;
            byte[] Buff;
            long n;
            n = 0;
            for (i = 1; (i <= S.Length); i = (i + 2)) {
                t1 = S.Substring((i - 1), 1);
                t2 = S.Substring(i, 1);
                k = ((mstr.IndexOf(t1, 0) + 1) 
                            - 1);
                m = ((mstr.IndexOf(t2, 0) + 1) 
                            - 1);
                j = m;
                (2 | 3);
                // TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
                m = ((m 
                            - (j * 2)) 
                            | 3);
                // TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
                object Preserve;
                Buff[n];
                Buff[n] = ((j * mstr.Length) 
                            + k);
                Buff[n] = Buff[n];
                m;
                n = (n + 1);
            }
            return StrConv(Buff, vbUnicode);
            
        acd:
            return "";
        }
      

  5.   

    C#-VB语言转换插件
    http://www.kamalpatel.net/convertcsharp2vb.aspx
    http://www.carlosag.net/tools/codetranslator/default.aspx