Modo correto de fazer um cast

Eu mostro como fazer o cast sem muita delonga e de forma simples e consistente

using System;

using System.Collections.Generic;

using System.Text;

class Program

{

static void Main()

{

int x;

long y = 10;

Console.WriteLine("cast\n----");

// cast consistente

x = (int)y;

Console.WriteLine("Consistente int = x = \u2192 long y = ", x , y);

// cast inconsistemnte

y = 2147483648;

x = (int)y;

Console.WriteLine("Inconsistente int = x \u2192 long y = ", x , y);

}

}

Artigos relacionados