c#的日常学习

更改文本位置、颜色    关键语句如下:

private void button1_Click(object sender, EventArgs e)

{

MessageBox.Show("你好!");

}

private void button2_Click(object sender, EventArgs e)

{

this.Text = "这是一个应用程序";

this.BackColor = Color.FromArgb(255, 255, 0);//颜色更改

this.label1.SetBounds(100, 100, 200, 50);//位置及大小

}

private void Form1_MouseMove(object sender, MouseEventArgs e)

{

this.label1.Text = e.X + "," + e.Y;//鼠标移动位置

}

常用的编程技术:

MessageBox.Show("你好!");

this.Text = "这是一个应用程序";

this.BackColor = Color.FromArgb(255, 255, 0);

this.label1.SetBounds(100, 100, 200, 50);

this.label1.Text = e.X + "," + e.Y;

Random rnd = new Random();//随机数对象

rnd.Next(255)//255以内

double a = double.Parse( textBox1.Text );//Parse用于解析

Console.WriteLine( "{0},{1}", a, b);

控制台输入、输出:

using System;

public class AppLineInOut 

{

    public static void Main(string[] args) 

    {

        string s = "";

        Console.Write("Please input a line: ");

        s = Console.ReadLine();

        Console.WriteLine("You have entered: {0}" , s );

    }

}

winform计算平方根:


private void button1_Click(object sender, EventArgs e)

{

    double a = double.Parse(textBox1.Text);

    double result = Math.Sqrt(a);

    label1.Text =  a + "的平方根是" + result.ToString();

}

使用技巧:

F7: 代码窗口

Shift+F7: 对象窗口

F4: 属性窗口

闪电图标: 对象的事件

F5: 编译及运行

Ctrl+F5: 编译及运行(不调试)

svm+两次Tab: static void Main( string[] args )

switch语句

using System;

public class GradeLevel{

    public static void Main( ){

        Console.Write("Input Grade Level: ");

        char grade = (char) Console.Read();

        switch( char.ToUpper( grade ) ){

            case 'A' : 

                Console.WriteLine(grade+" is 85~100");

                break;

            case 'B' : 

                Console.WriteLine(grade+" is 70~84");

                break;

            case 'C' : 

                Console.WriteLine(grade+" is 60~69");

                break;

            case 'D' : 

                Console.WriteLine(grade+" is <60");

                break;

            default : 

                Console.WriteLine("input error");

                break;

        }

    }

}

筛法求素数

using System;

public class PrimeFilter{

    public static void Main( string [] args ){

        int N = 100;

        bool [] a = new bool[N+1];

        for( int i=2; i<=N; i++ ) a[i]=true;

  

        for( int i=2; i<N; i++ )

        {

            if(a[i]) for( int j=i*2; j<=N; j+=i )

                a[j]=false;

        }

  

        for( int i=2; i<=N; i++) 

            if( a[i] ) Console.Write( i + " " );

    }

}

数组

//一维数组,二维数组,交叉数组空间都是动态分布,new 数据类型[长度] 方式申请空间,必要时可以再次重新对空间进行申请分配,相当于对数组长度进行改变
//一维数组 :int[] a=new int[length];或者用大括号进行初始化
//二维数组:int[,] aa=new int[rowLength,colLength];
//交叉数组:int[][] aaa=new int[rowLength][]; //第二维长度根据需要动态指定
// aaa[i] = new int[colLenth];
//数组访问可以用foreach方式进行访问;也可以用for语句访问,注意数组length

checkbox,radiobutton、checklistbox,dropdownlist,panel控件的使用

 string name, sex, favorites, city, eye;
            int age;
            name = txtName.Text;
            age =int.Parse( txtAge.Text);
            //单选按钮值取值时需要判断哪个被选中
            sex = "";
            if (rbSexMale.Checked)
            {
                sex = "男";
            }
            else if (rbSexFemale.Checked)
            {
                sex = "女";
            }
            if (rbEye_y.Checked)
            {
                eye = "是";
            }else
            {
                eye = "否";
            }
            favorites = "";
            //复选框判断是否选中要依次判断各个组件
            if (chkBascketball.Checked)
            {
                favorites += chkBascketball.Text+"|";

            }
            if (chkFootball.Checked)
            {
                favorites += chkFootball.Text + "|";

            }
            if (chkSkip.Checked)
            {
                favorites += chkSkip.Text + "|";

            }

            //下拉框判断选中,用selectedItem
            city = cbCity.SelectedItem.ToString();
            
            MessageBox.Show(name+","+age+","+sex+","+favorites+","+city);

windows窗体设计
一、基本控件
1.Form窗体
2.TextBox
3.Label
4.Button
5.Timer
6.RadioButton
7.CheckBox
8.ComboBox
9.菜单
二、控件常用属性
1.Text 文本读写
2.Visible 控件是否可见
3.Enable 控件是否可用
4.ReadOnly 控件内容只读
5.ForeColor
6.Location
7.Size
三、常用事件
Click
四、窗体间跳转

连接数据库举例

  SqlConnection ,SqlCommand,SqlConnectionStringBuilder的相关知识

 public SqlConnection getConnection() {
            //首先获取数据库连接信息的字符串;
            string str = "data source=(local);uid=sa;pwd=123456;database=newsdb";
            //建立数据库连接通道
            SqlConnection conn = new SqlConnection(str);
           // conn.Open();
            //conn.Close();

            return conn;
        
        }
//插入数据
insert into Category(cName,cEName,parentid,showOrder)
  values('校内新闻','school news',0,6)

数据库的信息一般放在配置文件(app.config)中的<ConnectionStrings>或者<AppSettings>标签中,读取时用ConfigrationManager静态类进行读取

 string str =  ConfigurationManager.ConnectionStrings["dbnews"].ConnectionString;

string str2 = ConfigurationManager.AppSettings["mydb"];

<configuration>
	<appSettings>
		<add key="mydb" value="data source=211.64.40.71;uid=sa;pwd=123456;database=newsdb"/>
	</appSettings>
	<connectionStrings>
		<add name="dbnews" connectionString="data source=211.64.40.71;uid=sa;pwd=123456;database=newsdb"/>
	</connectionStrings>
	
</configuration>

MVC结构
Model:表变成类
View:form表单
C:数据访问和控制层(前端和后端的交互控制)
Dal:Data Access layer

第三章重点掌握构造方法、属性方法的书写方式,函数的传值、传地址,以及运算符重载

明确protected private public 在继承和外部调用;子类覆盖或者隐藏父类方法的操作有哪几种(new(针对覆盖父类中一般的方法) override(针对父类方法含有virtual或者abstract));抽象类的定义,注意抽象类中函数只有声明没有实现
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hly8521

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值