/**
* Compilar: mcs Principal.cs
* Ejecutar: mono Principal.exe
*/
using System;
public class Principal{
public static void Main(string[] args){
Principal.mockA();
}
public static void mockA(){
//Tipos de valor(tipos simples, tipos de numeracion, tipos de estructura y tipos de valores NULL)
//Tipos simples:
sbyte bsigned = -1;
short csigned = -21;
int esigned = -9;
long lsigned = -20000;
byte usigned = 1;
ushort cunsigned = 21;
uint eunsigned = 9;
ulong lunsigned = 20000;
char car = 'A';
float flotante = 23.0f;
double real = 30.222;
decimal dec = 12;
bool verdadero = false;
string cadena = "El asesinato del cardenal.";
Console.WriteLine("{0}",cadena);
Console.WriteLine(car);
Console.WriteLine(""+verdadero);
int[] numeros = new int[] {1,2,3,4,5,6};
Console.WriteLine(numeros);//System.Int32[]
Frutas fruta = Frutas.MANZANA;
Console.WriteLine(fruta);//MANZANA
fruta = Frutas.PERA;
switch (fruta){
case Frutas.MANZANA:
Console.WriteLine("Te gustan las manzanas");
break;
case Frutas.DURAZNO:
Console.WriteLine("Te gustan los duraznos");
break;
default:
Console.WriteLine("Probablemente te gustan las peras");
break;
}
try{
object o = eunsigned;//boxing
int e = (int) o; //unboxing
}catch(Exception ex){
Console.WriteLine("Ha ocurrido una excepcion en el Cast: {0}",ex.Message);
}
try{
int division = 2 / int.Parse("0");
}catch(Exception ex){
Console.WriteLine("Ha ocurrido una excepcion en la division.");
Console.WriteLine("HelpLink = {0}", ex.HelpLink);
Console.WriteLine("Message = {0}", ex.Message);
Console.WriteLine("Source = {0}", ex.Source);
Console.WriteLine("StackTrace = {0}", ex.StackTrace);
Console.WriteLine("TargetSite = {0}", ex.TargetSite);
}
string nada = null;
X my_x = new X();
Televisor my_televisor = new Televisor();
my_televisor.Marca = "Whirpool";
Console.WriteLine("Marca: {0}",my_televisor.Marca);
}
enum Frutas{
MANZANA, PERA, DURAZNO
};
}
class X{}
class Televisor{
private string marca;
public Televisor(){}
public Televisor(string marca){
this.marca=marca;
}
public string Marca{
get{ return this.marca; }
set{ this.marca=value; }
}
//Otra forma:
//public string Marca{get; set;}
//Otra forma:
//public string Marca{get; private set;}
//Otra forma (inicializando variables):
//public string Marca{get; set;} = "Whirpool";
}
Ejemplo de código en csharp (C#)
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.