Skip to content

Upcast and downcast

CodingUnit edited this page Nov 28, 2011 · 3 revisions

Upcast and downcast

  • Category: Defining Types and Functions
  • Description: Use upcast and downcast
  • Code:
using System;
using System.Console;

def UpcastDownCastSample1()
{
    def a = 10;
    def upcastFunction(x) { x : object }
    def downcastFunction(x) {x :> int }
    def objValue = upcastFunction(a);
    WriteLine($"name = $objValue");
    WriteLine($"int = $(downcastFunction(objValue))")
}

UpcastDownCastSample1()
  • Execution Result:
name = 10
int = 10

  • Copyright
Samples used from "F# 3.0 Sample Pack" (http://fsharp3sample.codeplex.com/) at Codeplex OpenSource Community for non-commercial usage. All copyrights and authorship on materials this publication based on, is belongs to Microsoft corp. Copyright © 2006-2011 Microsoft Corporation, . All rights reserved. Copyright and autorship for materials in Nemerle language belongs to Nemerle Project Team. Copyright © 2008-2011 Nemerle Project Team. All rights reserved.
Clone this wiki locally