zoukankan      html  css  js  c++  java
  • 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+" dbjobtypeDB.mdb";
                       OleDbConnection connection = new OleDbConnection(strCon);
            }
        }
    }
  • 相关阅读:
    linux查看CPU和内存信息
    linux yum命令详解
    查看文件中关键字前后几行的内容
    vue.js+web storm安装及第一个vue.js
    android GPS: code should explicitly check to see if permission is available
    ASP.NET MVC Identity 使用自己的SQL Server数据库
    阿里云服务器,tomcat启动,一直卡在At least one JAR was scanned for TLDs yet contained no TLDs就不动了
    ASP.NET MVC4 MVC 当前上下文中不存在名称“Scripts”
    python 将windows字体中的汉字生成图片的方法
    Java android DES+Base64加密解密
  • 原文地址:https://www.cnblogs.com/ruishuang208/p/3322160.html
Copyright © 2011-2022 走看看