c#第一次作业
来源:互联网 发布:linux root为用户授权 编辑:程序博客网 时间:2024/05/16 09:49
程序代码如下:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string fileacc;
- // 总行数
- int lineA = 0;
- //代码行数
- int lineB = 0;
- //注释行数
- int lineC = 0;
- //空白行数
- int lineD = 0;
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //当文件地址有效时
- try
- {
- fileacc = textBox1.Text;
- FileStream file = new FileStream(@fileacc, FileMode.Open);
- StreamReader lq = new StreamReader(file);
- string line = lq.ReadLine();
- while (line != null)
- {
- lineA++;
- if (line.Trim() != "" && !(line.Trim().StartsWith(@"//")))
- {
- lineB++;
- }
- else if (line.Trim().StartsWith(@"//"))
- {
- lineC++;
- }
- else
- {
- lineD++;
- }
- line = lq.ReadLine();
- }
- lq.Close();
- //统计完成后弹出统计成功的消息框
- MessageBox.Show("统计成功");
- //显示统计结果
- label3.Text = lineA.ToString();
- label5.Text = lineB.ToString();
- label7.Text = lineC.ToString();
- label9.Text = lineD.ToString();
- }
- //当文件地址无效时
- catch
- {
- //弹出文件地址无效,请重新输入的消息框
- MessageBox.Show("文件地址无效,请重新输入!");
- }
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- }
- }
- }
开始时界面
统计成功时
统计结果
失败时
0 0
- C#作业(第一次)
- C# 第一次作业
- c#第一次作业
- C#第一次作业
- c#第一次作业
- C#第一次作业
- C#第一次作业
- c#第一次作业
- 第一次C#作业
- 郭静梅 第一次c#作业源代码计算器
- 第一次C#作业(代码行统计)
- 第一次作业
- 第一次作业
- 第一次作业
- 第一次作业
- 第一次作业
- 第一次作业
- 第一次作业
- LINUX中LVM的创建,扩容,增减大小
- vc++下 asci函数与unicode对照
- UNION和UNION ALL区别
- HDU-2028
- Android自定义软键盘的实现
- c#第一次作业
- 线性表的顺序存储
- 黑马程序员--关于控件平移缩放旋转的总结
- 如何写简单的Makefile
- 黑马程序员-IOS学习笔记 结构体的嵌套demo
- 浏览器输入网址后台怎么运行
- 在android中创建包含对象数组对象List 的Parcelable
- It's because your R is too old
- HashMap和Hashtable的区别