Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要一个VB.NET中使用的C#类的工作示例_C#_Vb.net_Dll - Fatal编程技术网

需要一个VB.NET中使用的C#类的工作示例

需要一个VB.NET中使用的C#类的工作示例,c#,vb.net,dll,C#,Vb.net,Dll,有谁能给我一个可以编译成DLL的C#类的简短工作示例,以及一个基于该类并使用其成员(方法)创建对象的VB.NET代码示例。C#类必须有一个名称空间、至少一个类定义(显然)和一些方法或任何应该调用的方法。我有其他人的C#-DLL代码,但在我的VB项目中看不到它的成员。我知道我必须在我的VB.NET项目中引用DLL。我正在使用VB.NET Express 2008和C#2008 Express。托管程序集(DLL和EXE)不是“C#”或“VB.NET”或任何其他语言 它们是.NET程序集,可以与任何

有谁能给我一个可以编译成DLL的C#类的简短工作示例,以及一个基于该类并使用其成员(方法)创建对象的VB.NET代码示例。C#类必须有一个名称空间、至少一个类定义(显然)和一些方法或任何应该调用的方法。我有其他人的C#-DLL代码,但在我的VB项目中看不到它的成员。我知道我必须在我的VB.NET项目中引用DLL。我正在使用VB.NET Express 2008和C#2008 Express。

托管程序集(DLL和EXE)不是“C#”或“VB.NET”或任何其他语言

它们是.NET程序集,可以与任何.NET语言进行互操作

在项目中引用此类程序集后,就可以访问其中的所有公共类型

如果您看不到任何成员,请确保它们确实声明为
public
,因为大多数成员的C#将默认为
internal
private

阅读有关C#中访问修饰符的详细信息。

托管程序集(DLL和EXE)不是“C#”或“VB.NET”或任何其他语言

它们是.NET程序集,可以与任何.NET语言进行互操作

在项目中引用此类程序集后,就可以访问其中的所有公共类型

如果您看不到任何成员,请确保它们确实声明为
public
,因为大多数成员的C#将默认为
internal
private

阅读更多关于C#中访问修饰符的信息。

需要一些工作吗?如果你有代码,并且熟悉VB。。。在VB中工作

有一个在步骤2中使用C#作为类库的示例。还有一个示例应用程序。

需要一些工作吗?如果你有代码,并且熟悉VB。。。在VB中工作


有一个在步骤2中使用C#作为类库的示例。还有一个示例应用程序。

我的猜测是,您试图访问的成员只是没有声明为
public
,因此它们不能跨名称空间使用

如果您想要一个工作示例,只需创建一个新的解决方案,并按照以下步骤操作即可

  • 添加VB.net代码项目
  • 添加一个公共类
  • 添加一个C#代码项目
  • 添加一个简单的C#类
  • 完成此设置后,只需从一个项目引用到另一个项目,并尝试在其中一个创建的类中调用它


    您可以对任何.Net dll执行此操作,只要成员声明为公共的,或者命名空间相同,并且成员声明为
    internal

    我猜您尝试访问的成员只是没有声明为
    public
    ,因此它们不能跨命名空间使用

    如果您想要一个工作示例,只需创建一个新的解决方案,并按照以下步骤操作即可

  • 添加VB.net代码项目
  • 添加一个公共类
  • 添加一个C#代码项目
  • 添加一个简单的C#类
  • 完成此设置后,只需从一个项目引用到另一个项目,并尝试在其中一个创建的类中调用它

    您可以对任何.Net dll执行此操作,只要成员声明为public或命名空间相同,并且成员声明为
    internal

    -foo.cs

    --bar.vb

    --要编译的批处理文件

    %WINDIR%\Microsoft.NET\Framework\v3.5\csc.exe /target:library foo.cs 
    %WINDIR%\Microsoft.NET\Framework\v3.5\vbc.exe bar.vb /reference:foo.dll
    
    --运行bar.exe

    -foo.cs

    --bar.vb

    --要编译的批处理文件

    %WINDIR%\Microsoft.NET\Framework\v3.5\csc.exe /target:library foo.cs 
    %WINDIR%\Microsoft.NET\Framework\v3.5\vbc.exe bar.vb /reference:foo.dll
    

    --运行bar.exe

    这里是一个工作示例-我必须重命名C#代码中的一些
    ComputeFingerprint
    重载,以使VB.Net正确识别您要调用的特定重载。也许这些是您在上面提到的您无法解决的错误

    C#代码:


    下面是一个工作示例-我必须重命名C#代码中的一些
    ComputeFingerprint
    重载,以使VB.Net正确识别您要调用的特定重载。也许这些是您在上面提到的您无法解决的错误

    C#代码:



    你有密码吗?或者仅仅是DLL?这不是dup,但它是它的后续版本。一般来说,应该可以工作,您需要更具体地了解哪些DLL和/或哪些成员您看不到。你怎么能看不到他们?在对象浏览器中,intellisense还是什么?@WernerCD:我有代码,并使用C#Express 2008构建了DLL。@Steve Townsend:没错,但我被卡住了,我想我对C#和VB.NET在这方面还不太了解。你有代码吗?或者仅仅是DLL?这不是dup,但它是它的后续版本。一般来说,应该可以工作,您需要更具体地了解哪些DLL和/或哪些成员您看不到。你怎么能看不到他们?在对象浏览器中,intellisense还是什么?@WernerCD:我有代码并使用C#Express 2008构建了DLL。@Steve Townsend:没错,但我被卡住了,我想我对C#和VB.NET在这方面的了解还不够。我试图将其转换为VB,但出现了一些无法解决的错误。但是请忘记那个DLL,请给我一个实际工作的简短例子。从那里我可能可以解决我真正的问题。我试图将它转换为VB,但得到了一些我无法解决的错误。但是请忘记那个DLL,请给我一个实际工作的简短例子。从那里我可能能够解决我真正的问题。+1提供运行测试所需的一切,甚至包括批编译命令。太棒了。谢谢你的回答,确实非常有用。+1提供了运行测试所需的一切,甚至包括批编译命令。太棒了。谢谢你的回答,真的很有帮助。史蒂夫,非常感谢你的帮助。我想让你知道上面的代码对我有用。我希望你不介意我选择daddyman的答案作为这个问题的“答案”,尽管你的答案也可以。Steve,非常感谢你的帮助。我想让
    %WINDIR%\Microsoft.NET\Framework\v3.5\csc.exe /target:library foo.cs 
    %WINDIR%\Microsoft.NET\Framework\v3.5\vbc.exe bar.vb /reference:foo.dll
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace RF
    {
    
        /// <summary>
        /// Génère des empreintes de fichiers
        /// </summary>
        public static class RabinFingerprint
        {
            /// <summary>
            /// Bit 64 of the polynomial P is always 1 and not treated directly. This is the polynomial
            /// with the leading coefficient removed (lcr).
            /// Represents t^64 + t^4 + t^3 + t + 1.
            /// </summary>
            private static readonly UInt64 p_lcr = 0x000000000000001BL;
            /// <summary>
            /// It's not necessary to provide definitions for such integral constant variables as long as their
            /// addresses are not taken.
            /// Degree of the polynomial P.
            /// </summary>
            private static readonly int K = 64;
            /// <summary>
            /// Represents t^(K-1)
            /// </summary>
            private static readonly UInt64 T_K_minus_1 = (UInt64)1L << (K - 1);
            /// <summary>
            /// Broder's paper presents four pre-computed tables because words are considered to be 32-bit.
            /// In this implementation W is a 64-bit integral type. Eight tables are used.
            /// Table A is i1^127 + i2^126 + ... + i8^120.
            /// Table B is i1^119 + i2^118 + ... + i8^112.
            /// Table C, D, ..
            /// Table E is i1^95  + i2^94  + ... + i8^88. (This is table A in the paper.)
            /// Table F, G, H.
            /// </summary>
            private static UInt64[] tableA_ = new UInt64[256]; //Assuming byte size 8.
            private static UInt64[] tableB_ = new UInt64[256];
            private static UInt64[] tableC_ = new UInt64[256];
            private static UInt64[] tableD_ = new UInt64[256];
            private static UInt64[] tableE_ = new UInt64[256];
            private static UInt64[] tableF_ = new UInt64[256];
            private static UInt64[] tableG_ = new UInt64[256];
            private static UInt64[] tableH_ = new UInt64[256];
            /// <summary>
            /// Constructor
            /// </summary>
            static RabinFingerprint()
            {
                InitTables();
            }
            /// <summary>
            /// Initialize tables
            /// </summary>
            private static void InitTables()
            {
                //This represents t^(k + i) mod P, where i is the index of the array.
                //It will be used to compute the tables.
                UInt64[] mods = new UInt64[K];
                //Remember t^k mod P is equivalent to p_lcr.
                mods[0] = p_lcr;
                for (int i = 1; i < K; ++i)
                {
                    //By property: t^i mod P = t(t^(i - 1)) mod P.
                    mods[i] = mods[i - 1] << 1;
                    //If mods[i - 1] had a term at k-1, mods[i] would have had the term k, which is not represented.
                    //The term k would account for exactly one more division by P. Then, the effect is the same
                    //as adding p_lcr to the mod.
                    if ((mods[i - 1] & T_K_minus_1) != 0)
                        mods[i] ^= p_lcr;
                }
                //Compute tables. A control variable is used to indicate whether the current bit should be
                //considered.
                for (int i = 0; i < 256; ++i)
                {
                    int control = i;
                    for (int j = 0; j < 8 && control > 0; ++j)
                    {
                        // bool.Parse(Convert.ToString())
                        if ((control & 1) == 1) //Ok, consider bit. ((byte))
                        {
                            tableA_[i] ^= mods[j + 56];
                            tableB_[i] ^= mods[j + 48];
                            tableC_[i] ^= mods[j + 40];
                            tableD_[i] ^= mods[j + 32];
                            tableE_[i] ^= mods[j + 24];
                            tableF_[i] ^= mods[j + 16];
                            tableG_[i] ^= mods[j + 8];
                            tableH_[i] ^= mods[j];
                        }
                        control >>= 1;
                    }
                }
            }
    
            /// <summary>
            /// Compute hash key
            /// </summary>
            /// <param name="value">Value to hash</param>
            /// <returns>Value</returns>
            private static UInt64 ComputeTablesSum(ref UInt64 value)
            {
                value = tableH_[((value) & 0xFF)] ^
                        tableG_[((value >> 8) & 0xFF)] ^
                        tableF_[((value >> 16) & 0xFF)] ^
                        tableE_[((value >> 24) & 0xFF)] ^
                        tableD_[((value >> 32) & 0xFF)] ^
                        tableC_[((value >> 40) & 0xFF)] ^
                        tableB_[((value >> 48) & 0xFF)] ^
                        tableA_[((value >> 56) & 0xFF)];
                return value; //Pass by reference to return the same w. (Convenience and efficiency.)
            }
            /// <summary>
            /// Compute hask hey
            /// </summary>
            /// <param name="HashArray">Array of Ulong bytes to ahsh</param>
            /// <returns>Hash key</returns>
            private static UInt64 Compute(UInt64[] HashArray)
            {
                UInt64 w = 0L;
                for (int s = 0; s < HashArray.Length; ++s)
                    w = ComputeTablesSum(ref w) ^ HashArray[s];
                return w;
            }
            /// <summary>
            /// Compute the fingerprint
            /// </summary>
            /// <param name="source">String to compute</param>
            /// <returns>Hash key</returns>
            public static UInt64 ComputeFingerPrint(string source)
            {
                byte[] table = Encoding.Unicode.GetBytes(source);
                UInt64[] values = new UInt64[table.LongLength];
                ConvertBytes(ref table, ref values);
                return Compute(values);
            }
            /// <summary>
            /// Compute the fingerprint, you must use this method for very large text
            /// </summary>
            /// <param name="source">String to compute</param>
            /// <returns>Hash key</returns>
            public static UInt64 ComputeFingerPrint2(ref string source)
            {
                return ComputeFingerPrint(source);
            }
            /// <summary>
            /// Compute the fingerprint, you must use this method for very large binary data
            /// </summary>
            /// <param name="source">Data to compute</param>
            /// <returns>Hash key</returns>
            public static UInt64 ComputeFingerPrint3(ref byte[] source)
            {
                UInt64[] values = new UInt64[source.LongLength];
                ConvertBytes(ref source, ref values);
                return Compute(values);
            }
            /// <summary>
            /// Compute the fingerprint, you must use this method for very large binary data
            /// </summary>
            /// <param name="source">Data to compute</param>
            /// <returns>Hash key</returns>
            public static UInt64 ComputeFingerPrint4(byte[] source)
            {
                return ComputeFingerPrint3(ref source);
            }
            /// <summary>
            /// Compute byte array to Uint64 array
            /// </summary>
            /// <param name="source">Table de byte source</param>
            /// <param name="destination">Tableau de Uin64</param>
            private static void ConvertBytes(ref byte[] source, ref UInt64[] destination)
            {
                for (long i = 0; i < source.LongLength; i++)
                    destination[i] = Convert.ToUInt64(source[i]);
            }
        }
    }
    
    Imports RF
    
    Module Module1
    
        Sub Main()
    
            Dim input = "this is the string"
            Dim result = RF.RabinFingerprint.ComputeFingerprint(input)
    
        End Sub
    
    End Module