asp net 3.5unleashed

Page 173

return Nothing End Function End Class The second one is a C# application that adds two instances of VBType:

using System; public class CSharpApp { public static void Main() { // Construct an instance of VBType. VBType vb = new VBType(); // When not commented out, the following line produces a // compiler error because VBType’s op_Addition method is missing // the specialname metadata flag. // vb = vb + vb; // The following line compiles and runs; it just doesn’t look nice. vb = VBType.op_Addition(vb, vb); } } As you can see from the preceding code, the C# code can’t use the + symbol to add two VBType objects together. However, it can add the objects together by explicitly calling VBType’s op_Addition method. Now let’s reverse the example and build a Visual Basic application that uses a C# type. Here’s a C# type (defined in a library) that offers an overload of the + operator:

using System; public class CSharpType { // Overload the + operator public static CSharpType operator+(CSharpType a, CSharpType b) { return null; } } And here’s a Visual Basic application that adds two instances of the CSharpType:

Imports System Public Class VBApp Public Shared Sub Main() ‘ Construct an instance of the CSharpType. Dim cs as new CSharpType()


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.