Complete Comparison for VB.NET and C# http://www.codeproject.com/dotnet/vbnet_c__difference.aspsome of the things in the above article might not be true in .NET 2.0 any more
学习了。看了那贴才知道vb.net还有catch when这么写的。
看到个c#调用api的,说是 use Platform Invoke 难道可以不用声明?楼下的解释以下好不好
C#中的运算符重载以下这句public static Complex operator +(Complex c1, Complex c2),如何在vb.net中实现?// complex.cs using System;public struct Complex { public int real; public int imaginary; public Complex(int real, int imaginary) { this.real = real; this.imaginary = imaginary; } // Declare which operator to overload (+), the types // that can be added (two Complex objects), and the // return type (Complex): public static Complex operator +(Complex c1, Complex c2) { return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary); } // Override the ToString method to display an complex number in the suitable format: public override string ToString() { return(String.Format("{0} + {1}i", real, imaginary)); } public static void Main() { Complex num1 = new Complex(2,3); Complex num2 = new Complex(3,4); // Add two Complex objects (num1 and num2) through the // overloaded plus operator: Complex sum = num1 + num2; // Print the numbers and the sum using the overriden ToString method: Console.WriteLine("First complex number: {0}",num1); Console.WriteLine("Second complex number: {0}",num2); Console.WriteLine("The sum of the two numbers: {0}",sum);
http://www.codeproject.com/dotnet/vbnet_c__difference.aspsome of the things in the above article might not be true in .NET 2.0 any more
难道可以不用声明?楼下的解释以下好不好
{
add
{
Debug.WriteLine("add called");
Click += value;
}
remove
{
Debug.WriteLine("remove called");
Click -= value;
}
}in VB.NET, seehttp://www.informit.com/articles/article.asp?p=31535&rl=1
using System;public struct Complex
{
public int real;
public int imaginary; public Complex(int real, int imaginary)
{
this.real = real;
this.imaginary = imaginary;
} // Declare which operator to overload (+), the types
// that can be added (two Complex objects), and the
// return type (Complex):
public static Complex operator +(Complex c1, Complex c2)
{
return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
}
// Override the ToString method to display an complex number in the suitable format:
public override string ToString()
{
return(String.Format("{0} + {1}i", real, imaginary));
} public static void Main()
{
Complex num1 = new Complex(2,3);
Complex num2 = new Complex(3,4); // Add two Complex objects (num1 and num2) through the
// overloaded plus operator:
Complex sum = num1 + num2; // Print the numbers and the sum using the overriden ToString method:
Console.WriteLine("First complex number: {0}",num1);
Console.WriteLine("Second complex number: {0}",num2);
Console.WriteLine("The sum of the two numbers: {0}",sum);
}
}
C#可以访问.net framework所提供的基类,且该类库有完整的参考(在MSDN .NET 2003中);
而VB不可以
该类库功能强大且完整,象智能嵌入设备的开发,USB设备的访问,GDI+绘图,尤其涉及到网络的类库都封装的非常好.这样,才为.NET各种语言快速高效的完成各种应用提供了保证.
可以说,学C#实际意义不大,只是一种工具和手段,实际开发还是靠该类库的掌握.最最重要的一点,该类库全部是中文的.
这一点vb可就不行了,做为一种语言,其实哪种语言都好,但做开发不一样,不可能各种对象都自己从底层写吧?所以,组件的支持非常重要,VB也不是没有好的组件支持,而是各个组件没有统一的使用规范和习惯,要命的是,帮助非常难找.
VB也有可能能够访问.net framework基类库,但使用起来绝对不会象C#那样高校和方便
其他在.net下,VB.net和C#基本上是同等的.不知 chenlixin007(Aeolus)为什么发表这们的高见呢?
unsafe 关键字表示不安全上下文,该上下文是任何涉及指针的操作所必需的。
可以在类型或成员的声明中使用 unsafe 修饰符。因此,类型或成员的整个正文范围均被视为不安全上下文。例如,以下是用 unsafe 修饰符声明的方法:
unsafe static void FastCopy ( byte[] src, byte[] dst, int count )
{
// unsafe context: can use pointers here
}
不安全上下文的范围从参数列表扩展到方法的结尾,因此指针在以下参数列表中也可以使用:
unsafe static void FastCopy ( byte* ps, byte* pd, int count ) {...}
还可以使用不安全块从而能够使用该块内的不安全代码。例如:
unsafe
{
// unsafe context: can use pointers here
}
若要编译不安全代码,必须指定 /unsafe 编译器选项。无法通过公共语言运行库验证不安全代码。
示例
// cs_unsafe_keyword.cs
// compile with: /unsafe
using System;
class UnsafeTest
{
// unsafe method: takes pointer to int:
unsafe static void SquarePtrParam (int* p)
{
*p *= *p;
}
unsafe public static void Main()
{
int i = 5;
// unsafe method: uses address-of operator (&)
SquarePtrParam (&i);
Console.WriteLine (i);
}
}
输出
25
搂主在问Vb和C#的区别,又不是在问VB.NET和C#的区别。
个人认为要是VB.NET、C#.NET、C++.NET和J#作比较,意义不大,都是.net framework派生出来的语言,你说他们功能上有多大区别?
所以说,学.NET,重要的.net framework,不过听说很遗憾的是,听说新一代程序构架要转为什么好像是B什么打头的了。而且,.NET下的语言必须要有.net framework的支持,跟老程序的兼容性一点也不好。
看来还是老语言有生命力,我现在正在学习VC++(6.0)或者VB(6.0),准备放弃.NET,各位同志,大家在这努力吧。