C#操作6-10

第六题结构类型数据

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 第六题
{
    struct Student
    {
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string sex;

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }
        int age;

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        int height;

        public int Height
        {
            get { return height; }
            set { height = value; }
        }
        int weight;

        public int Weight
        {
            get { return weight; }
            set { weight = value; }
        }


    }
}





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 第六题
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student();
            stu1.Name = "张三";
            stu1.Age = 21;
            stu1.Height = 180;
            stu1.Weight = 130;
            stu1.Sex = "";
        }
    }
}


第七题建立一个标签

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 第七题
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = this.label1.Text;
        }
    }
}

第八题成绩评优

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btConfirm_Click(object sender, EventArgs e)
        {
            int score;
            int n;
            score = Convert.ToInt32(tbScore.Text);
            n = score / 10;
            switch(n)
            {
                case 10:
                case 9:
                lbgraded.Text="成绩为优秀!";
                break;
                case 8:
                lbgraded.Text="成绩为良好!";
                break;
                case 7:
                lbgraded.Text="成绩为中等!";
                break;
                case 6:
                lbgraded.Text="成绩及为格!";
                break;
                case 5: 
        
                case 4:
               
                case 3:
              
                case 2:
             
                case 1:
           
                case 0:lbgraded.Text="成绩为不及格!";break;
                default:MessageBox.Show("输入的成级超过了范围,请输入!","提示框");break;

            }
        }
    }
}

第九题MyCalss类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 第九题
{
    class MyClass
    {
        #region 定义 public 类成员

        public string publicVar;

        public void publicMethod()
        {
            Console.WriteLine("您现在调用的是public类型的方法!");
        }

        #endregion

        #region 定义 protected 类成员

        protected string protectedVar;

        protected void protectedMethod()
        {
            Console.WriteLine("您现在调用的是protected类型的方法!");
        }

        #endregion

        #region 定义 private 类成员

        private string privateVar;

        private void privateMethod()
        {
            Console.WriteLine("您现在调用的是private类型的方法!");
        }

        #endregion
    }
}





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 第九题
{
    class MyMain:MyClass
    {

        
        
        public static void Main()
        {
            MyClass obj = new MyClass();

            //不会产生错误
            //1访问public修饰的成员

            obj.publicMethod();
            obj.publicVar = "test1";



            //将会产生编译错误,无法运行
            //2访问protected修饰的成员 

            //obj.protectedMethod();
            //obj.protectedVar = "test1";



            //将会产生编译错误,无法运行
            //3访问private修饰的成员

            //obj.privateMethod();
            //obj.privateVar = "test1";
  
        }
    }
}


第十题服务器地址

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace 第十题
{
    class Program
    {


        static void Main(string[] args)
        {
                   string strCon = "server =202.196.131.26;  database=test;  uid =sa;  pwd=administrator";
                   SqlConnection connection = new SqlConnection(strCon);


                   //获取当前应用程序的路径
                   string parth = Environment.CurrentDirectory;
                   string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+parth+" \db\jobtypeDB.mdb";
                   OleDbConnection connection = new OleDbConnection(strCon);
        }
    }
}

 

 

转载于:https://www.cnblogs.com/ruishuang208/p/3322160.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值