stackoverflow1453

Programming&&Games&&Life

Archive for April, 2015

How to check decimal separator and number group separator for your system?

            string numberDecimalSeparator = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
            string numberGroupSeparator = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberGroupSeparator;

            Console.WriteLine("Ondalik ayraciniz:{0}", numberDecimalSeparator);
            Console.WriteLine("Sayi grup ayraciniz:{0}", numberGroupSeparator);

Decimal

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Hesap
{
    private decimal bakiye;
        
    //property    
    public decimal Bakiye
    {
        get { return bakiye; }
        set { bakiye = value; }
    }

    //constructor
    public Hesap(decimal ilkpara)
    {
        Bakiye = ilkpara;
    }

    //method 1
    public void Yatir(decimal para)
    {
        Bakiye = Bakiye + para;
    }

    //method 2
    public void Mesaj()
    {
        Console.WriteLine("hesaptaki para: {0}", Bakiye);
    }
}

//====================================//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class test
{
    public static void Main(string[] args)
    {
        Hesap hesap1 = new Hesap(78.44M);
        Hesap hesap2 = new Hesap(23.89M);

        hesap1.Mesaj();
        hesap2.Mesaj();
        Console.Write("1.hesabiniza kac para yatiracaksiniz?: ");
        hesap1.Yatir(Convert.ToDecimal(Console.ReadLine()));
        hesap1.Mesaj();

    }

}

Constructor

using System;

public class Mobile
{
    private string marka;

    //property
    public string Marka
    {
        get { return marka; }
        set { marka = value; }
    }

    //constructor
    public Mobile(string isim)
    {
        Marka = isim;
    }

    //method
    public void mesajgoster()
    {
        Console.WriteLine("Cep telefonu markasi: {0}", marka);
    }
}

//========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Test
{
    public static void Main(string[] args)
    {
        //Created with constructor
        Mobile benimcebim = new Mobile("Samsung");
        Mobile onuncebi = new Mobile("Nokia");

        System.Console.WriteLine(benimcebim.Marka);
        System.Console.WriteLine(onuncebi.Marka);

        benimcebim.mesajgoster();

    }

}

Classes

using System;

public class Mobile
{
    private string marka;

    public string Marka
    {
        get { return marka; }
        set { marka = value; }
    }

    public void mesajgoster()
    {
        Console.WriteLine("Cep telefonu markasi: {0}",marka);
    }
}


//==================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Test
{
    public static void Main(string[] args)
    {
        Mobile benimcebim = new Mobile();
        Mobile onuncebi = new Mobile();

        benimcebim.Marka = "Samsung";
        onuncebi.Marka = "Nokia";

        System.Console.WriteLine(benimcebim.Marka);
        System.Console.WriteLine(onuncebi.Marka);

        benimcebim.mesajgoster();

    }

}

Reverse Polish Notation

module TheBookOfFSharp.RpnCalculator
open System
let evalRpnExpr (s : string) =
    let solve items current =
        match (current, items) with
        | "+", y::x::t -> (x + y)::t
        | "-", y::x::t -> (x - y)::t
        | "*", y::x::t -> (x * y)::t
        | "/", y::x::t -> (x / y)::t
        | _ -> (float current)::items
    (s.Split(' ') |> Seq.fold solve []).Head

[<EntryPoint>]
let main argv =
  [ "4 2 5 * + 1 3 2 * + /"
    "5 4 6 + /"
    "10 4 3 + 2 * -"
    "2 3 +"
    "90 34 12 33 55 66 + * - + -"
    "90 3 -" ]
  |> List.map (fun expr -> expr, evalRpnExpr expr)
  |> List.iter (fun (expr, result) -> printfn "(%s) = %A" expr result)
  Console.ReadLine() |> ignore
  0

Printing current time

open System
let today=DateTime.Now
System.Console.WriteLine(today)

1st F# Program

open System
System.Console.WriteLine "Hello World"
Console.ReadLine()