Csharp/C Sharp/Data Types/Parse

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

bool.Parse

 
using System;
using System.Collections.Generic;
using System.Text;
class Program {
    static void Main(string[] args) {
        bool myBool = bool.Parse("True");
        Console.WriteLine("-> Value of myBool: {0}", myBool);
    }
}


char.Parse

 
using System;
using System.Collections.Generic;
using System.Text;
class Program {
    static void Main(string[] args) {
        char myChar = char.Parse("w");
        Console.WriteLine("-> Value of myChar: {0}\n", myChar);
    }
}


double.Parse

 
using System;
using System.Collections.Generic;
using System.Text;
class Program {
    static void Main(string[] args) {
        double myDbl = double.Parse("99.884");
        Console.WriteLine("-> Value of myDbl: {0}", myDbl);
    }
}


int.Parse

 
using System;
using System.Collections.Generic;
using System.Text;
class Program {
    static void Main(string[] args) {
        int myInt = int.Parse("8");
        Console.WriteLine("-> Value of myInt: {0}", myInt);
    }
}


parse decimal

 
using System;
public class Class1 {
    public static void Main(string[] args) {
        Console.Write("Enter principal:");
        string sPrincipal = Console.ReadLine();
        decimal mPrincipal = decimal.Parse(sPrincipal);
        Console.Write("Enter interest:");
        string sInterest = Console.ReadLine();
        decimal mInterest = decimal.Parse(sInterest);
        decimal mInterestPaid;
        mInterestPaid = mPrincipal * (mInterest / 100);
        decimal mTotal = mPrincipal + mInterestPaid;
        Console.WriteLine("Principal     = " + mPrincipal);
        Console.WriteLine("Interest      = " + mInterest + "%");
        Console.WriteLine("Interest paid = " + mInterestPaid);
        Console.WriteLine("Total         = " + mTotal);
    }
}