c# - C# 和 VB.Net 自定义类之间的区别

标签 c# vb.net

我已经离开 VB.Net 太久了,我有一个 C# 自定义类需要转换为 VB.Net,并且想知道它们之间的主要区别。 C# 中的某些事情我似乎无法在 Vb.Net 中使用类执行,例如 use: public classname 或 public [classname](DataTable dt) in VB.net

我的类(class)如下所示:

public class subcontractor
{
    public int organization_id { get; set; }
    public int subcontractor_id { get; set; }
    public int project_id { get; set; }
    public List<evaluationpoint> points { get; set; }

    public subcontractor() { }
    public subcontractor(DataTable dt)
    {
        organization_id = Convert.ToInt32(dt.Rows[0]["organization_id"].ToString());
        subcontractor_id = Convert.ToInt32(dt.Rows[0]["subcontractor_id"].ToString());
        project_id = Convert.ToInt32(dt.Rows[0]["project_id"].ToString());
        points = new List<evaluationpoint>();
        foreach ( DataRow dr in dt.Rows )
        { points.Add(new evaluationpoint(dr)); }
    }

    public class evaluationpoint
    {
        public int category_id { get; set; }
        public int eval_id { get; set; }
        public int rating { get; set; }

        public evaluationpoint() { }
        public evaluationpoint(DataRow dr)
        {
            category_id = Convert.ToInt32(dr["category_id"].ToString());
            eval_id = Convert.ToInt32(dr["eval_id"].ToString());
            rating = Convert.ToInt32(dr["rating"].ToString());
        }
    }
}

有什么区别

最佳答案

首先,read this

VB.NET 中的构造函数在语法上有所不同:

C#

Class Foo
{
    public Foo( int arg ) { }
}

VB

Class Foo
    Public Sub New( ByVal arg as Integer )

    End Sub
End Class

大多数情况下,您可以在 VB.NET 中执行 C# 中可以执行的任何操作,只需适当更改语法即可。那里有很多引用资料,请充分利用。

关于c# - C# 和 VB.Net 自定义类之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7277037/

相关文章:

c# - 通知线程停止的选项

c# - 从抽象集合中生成抽象集合

c++ - 如何判断我使用的库、dll 和函数是否是 C++ Native

vb.net - 你如何在 VB .NET 中将 Double 向下舍入到最接近的整数?

c# - .Net 数值类型初始化标识符列表

c# - 一对多关系映射 : Cannot add or update a child row: a foreign key constraint fails

c# - 使用自定义对象将数据绑定(bind)到 datagridview - 列标题文本

c# - 逆向工程 asp.net web 应用程序

asp.net - VS2013构建 View 时脚手架错误

c# - 如何解析 set-cookie header 中的名称-值对?