我已经离开 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/