using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace conversii
{
class intreg
{
private int n;
public intreg() { n = 0; }//constructor
public intreg(int n) { this.n = n; }//constructor
public static explicit operator intreg(int v)
{//conv. explicita int->intreg
return new intreg(v);
}
public static explicit operator int(intreg v)
{//conv. explicita integ->int
return v.n;
}
}
class real
{
private double n;
public real() { n = 0; }//constructor
public real(double n) { this.n = n; }//constructor
public static implicit operator real(double v)
{//conv. implicita double->real
return new real(v);
}
public static implicit operator double(real v)
{//conv. implicita real->double
return v.n;
}
}
class Program
{
static void Main(string[] args)
{
int x=7;
intreg y;//numar intreg
y = (intreg)x;//convertesc pe x la intreg si dau lui y
Console.WriteLine((int)y);//convertesc pe y la int si afisez
double pi = 3.1415;
real p;//numar real
p = pi;//atribuire cu conv implicita
Console.WriteLine(p);//conv implicita pt afisare
Console.ReadKey();
}
}
}
|