c# 代碼整理集 3

7 簡單數據綁定
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Bindings
{
    
public partial class Form1 : Form
    
{
        data d1;
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            d1
=new data ();
            
this.label1.DataBindings.Add("Text", d1, "Text");
            
this.textBox1.DataBindings.Add("Text", d1, "Text");
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            d1.Text 
= "this is a test!";
        }

    }


    
public class data
    
{
        
private string text;

        
public string Text
        
{
            
get
            
{
                
return this.text;
            }

            
set
            
{
                
this.text = value;
            }

        }


        
public data()
        
{
            
this.text = "";
        }

    }

}

8 float 轉 int 時,會不會四捨五入?
        static void Main(string[] args)
        {
            float f = -123.567F;
            int i = (int)f;
             //i =-123
        }
9 ToString 參數影響的結果。
        static void Main(string[] args)
        
{

            
double a;
            a 
= 1222.05;
            Console.Write(a.ToString(
"# "));                       //1222
            Console.Write(a.ToString("## "));                      //1222
            Console.Write(a.ToString("##.# "));                    //1222.1
            Console.Write(a.ToString("##.## "));                   //1222.05
            Console.Write(a.ToString("####.### "));                //1222.05    
            Console.Write(a.ToString("####.###### "));             //1222.05    
            Console.Write(a.ToString("#############.######## "));  //1222.05
            Console.Write(a.ToString("##.0 "));                    //1222.1
            Console.Write(a.ToString("(##)##.0 "));                //(12)22.1    
            string s=Console.ReadLine();


        }


 
發佈了13 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章