namespace First { public class Point { private int iX; private int iY; public Point(int pX, int pY) { iX = pX; iY = pY; } public override string ToString() { return iX + ":" + iY; } } }
using System; namespace First { public class PointTest { public static void Main() { Point tPoint = new Point(100, 200); Console.WriteLine(tPoint); Point tAnotherPoint = tPoint; Console.WriteLine(tAnotherPoint); } } }
namespace First { public class NamedPoint : Point { private string iName; public NamedPoint(string pName, int pX, int pY) : base(pX, pY) { iName = pName; } public override string ToString() { return iName + "%" + base.ToString(); } } }
using System; namespace First { public class NamedPointTest { public static void Main() { NamedPoint tNamedPoint = new NamedPoint("first", 100, 200); Console.WriteLine(tNamedPoint); Point tPoint = tNamedPoint; Console.WriteLine(tPoint); } } }
Public Class Point Private iX As Integer Private iY As Integer Public Sub New(ByVal pX As Integer, ByVal pY As Integer) iX = pX iY = pY End Sub Public Overrides Function ToString() As String Return iX & ":" & iY End Function End Class
Module PointTest Sub Main() Dim tPoint As Point = New Point(100, 200) Console.WriteLine(tPoint) Dim tAnotherPoint As Point = tPoint Console.WriteLine(tAnotherPoint) End Sub End Module
Public Class NamedPoint Inherits Point Private iName As String Public Sub New(ByVal pName As String, ByVal pX As Integer, ByVal pY As Integer) MyBase.New(pX, pY) iName = pName End Sub Public Overrides Function ToString() As String Return iName & "%" & MyBase.ToString() End Function End Class
Module NamedPointTest Sub Main() Dim tNamedPoint As NamedPoint = New NamedPoint("first", 100, 200) Console.WriteLine(tNamedPoint) Dim tPoint As Point = tNamedPoint Console.WriteLine(tPoint) End Sub End Module
We have now provided 4 classes in both C# and VB.NET:
We can mix the languages, e.g., use C#'s NamedPointTest class with VB.NET's NamedPoint class and C#'s Point class.