Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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
C#和VB.Net自定义类之间的差异_C#_Vb.net - Fatal编程技术网

C#和VB.Net自定义类之间的差异

C#和VB.Net自定义类之间的差异,c#,vb.net,C#,Vb.net,我离开VB.Net太久了,我有一个C#中的自定义类,需要转换为VB.Net,我想知道它们之间的主要区别。C#中的某些事情在Vb.Net中似乎无法使用诸如Vb.Net中的use:public classname或public[classname](DataTable dt)之类的类 我的班级如下所示: public class subcontractor { public int organization_id { get; set; } public int subcontrac

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

我的班级如下所示:

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());
        }
    }
}
公共类分包商
{
公共int组织_id{get;set;}
公共int\u id{get;set;}
公共int项目_id{get;set;}
公共列表点{get;set;}
公共分包商(){}
公共分包商(数据表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());
点=新列表();
foreach(数据行dr在dt.行中)
{points.Add(新的评估点(dr));}
}
公共类评估点
{
公共int类_id{get;set;}
公共int eval_id{get;set;}
公共整数评级{get;set;}
公共评估点(){}
公共评估点(DataRow dr)
{
category_id=Convert.ToInt32(dr[“category_id”].ToString());
eval_id=Convert.ToInt32(dr[“eval_id”].ToString());
rating=Convert.ToInt32(dr[“rating”].ToString());
}
}
}

区别是什么

如果您的项目是在VB.NET中实现的,那么其他项目(甚至是C#项目)仍然可以调用VB.NET方法(反之亦然)

单个Visual Studio解决方案可以有VB.NET项目和C#项目。每个(使用正确的项目引用)都可以访问另一个的方法和类,因为它们都是.NET类,已编译成MSIL供CLR运行。

首先

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

C#

VB


在VB.NET中,你可以像在C#中那样做任何事情,你只需要适当地修改你的语法。有大量的参考资料,利用它。

构造函数的语法非常不同;例如,在C#中使用类名,在VB中使用New

Class SubContractor

   Public Sub New()
   End Sub

   Public Sub New(dt As DataTable)
   End Sub

End Class

关于这些差异有更具体的细节,包括构造函数/析构函数在这方面的差异。

我需要实际使用c#类并将其实现到VB.Net项目中。你是说我可以简单地将C#类放入我的VB.Net项目中,而不会产生任何问题吗?不,你可以做的是将C#库项目添加到解决方案中,将C#类添加到该项目中,然后从VB.Net项目中添加对该项目的引用。然后你可以从VB.net项目中访问你的C#类,你不必重写任何东西。我已经很久没有参与VB了,如果没有充分使用,这些东西就会从内存中消失。我知道语法有很大的不同,只是忘记了如何在自己内部建立一个新类,谢谢you@Guffa当前位置正如您所知,我不经常使用VB:)谢谢,我已经修复了它
Class Foo
    Public Sub New( ByVal arg as Integer )

    End Sub
End Class
Class SubContractor

   Public Sub New()
   End Sub

   Public Sub New(dt As DataTable)
   End Sub

End Class