C#学习

//十进制转二进制
string str = Convert.ToString(69, 2);


//十进制转八进制
string str = Convert.ToString(69, 8);


//十进制转十六进制
string str = Convert.ToString(69, 16);

//二进制转十进制
string str = Convert.ToInt32("100111101", 2);


//八进制转十进制
string str = Convert.ToInt32("76", 8);


//十六进制转十进制
string str = Convert.ToInt32("FF", 16);

 

//ToString中X代表转换为16进制的字符串格式,大小写x表示转换后字符串的大小写形式,x后面跟随数字:转换后的字符串长度,不足补零

int d = 18;

d.ToString("X4");

 

//练习九九乘法表

        System.Web.UI.HtmlControls.HtmlForm frm = this.form1;
        Label lb = new Label();
        lb.Text = "九九乘法表";
        lb.Style.Add("color","red");
        lb.Style.Add("font-size","18px");
        frm.Controls.Add(lb);
        for (int i = 1; i < 10;i++ )
        {
            for (int j = 1; j < 10;j++ )
            {
                if (j<=i)
                {
                    Button btn = new Button();
                    btn.Text = string.Format("{0}*{1}={2}",i,j,i*j);
                    btn.Attributes.Add("onclick", "alert(this.value);return false;");
                    btn.Style.Add("position", "absolute");
                    btn.Style.Add("left", string.Format("{0}px",j*75));
                    btn.Style.Add("top", string.Format("{0}px", i*25));
                    btn.Style.Add("width", "75px");
                    btn.Style.Add("height", "25px");
                    frm.Controls.Add(btn);
                }
                else
                {
                    break;
                }
            }
        }
 

 

 

posted @ 2011-04-06 17:36  Microbar  阅读(408)  评论(0编辑  收藏  举报