2009年12月19日土曜日

条件演算子?:を使用し、絶対値を求めるWebアプリケーションを作成してみる。
KMI - 絶対値を求める

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class AbsoluteValue : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        var a = Int32.Parse(TextBox1.Text);
        TextBox2.Text = String.Format("{0}", (0 <= a) ? a : (-a));
    }
}

0 コメント:

コメントを投稿