
化典成籍 - C#
你有你光鲜的生活,我有我自在的活法。
WanAkiko.
遇见是一种福气,不遇见也是。
展开
-
C#数据类型转换的三种方式
若两个变量的类型相兼容(同属于数字),可以使用自动类型转换或者强制类型转换;而当两个变量的类型不兼容时,例如 string 与 int 不相兼容,此时可使用 Convert 进行类型转换。 int Convert.ToInt32(string value); * 此方法可将字符串类型的数字转换为整数型数字,但有可能转换失败,其抛出异常时需要手动处理。 void int.Parse(string value); * 此方法可将字符串类型的数字转换为整数型数字,Convert.T原创 2020-07-26 08:42:02 · 1262 阅读 · 0 评论 -
C#使用文件流读取乱序文件并顺序编排
using System;using System.IO;using System.Collections.Generic;namespace Demo{ class Program { static void Main(string[] args) { // 声明文件读取流并指定文件位置 StreamReader reader = new StreamReader(@"C:\Users\Adminis原创 2020-10-26 15:24:28 · 469 阅读 · 2 评论 -
C#绘制窗体验证码
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;namespace VerCode{ public partial cl原创 2020-09-20 17:37:12 · 526 阅读 · 0 评论 -
C#线程幸运数摇奖机小程序
using System;using System.Threading;using System.Windows.Forms;namespace Ernie{ public partial class MainForm : Form { public MainForm() { InitializeComponent(); } bool flag = false; privat原创 2020-09-17 16:04:41 · 835 阅读 · 0 评论 -
C#自制简易音乐播放器
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;using System.IO;using System.Media;namespace Demo08_MusicPlayer{原创 2020-09-15 14:24:48 · 707 阅读 · 0 评论 -
C#图片浏览小程序
// 获取指定文件夹中所有文件的全路径string[] picPathArr = Directory.GetFiles(@"D:\Aggregate_Data\Documents\MyFiles\MyPicture\其他图片");int picIndex = 0; // 图片路径下标/// <summary>/// 从本地资源管理其中加载图片资源/// </summary>/// <param name="sender"></param>//原创 2020-09-14 16:51:44 · 311 阅读 · 0 评论 -
C#子窗体在父窗体中的排列方式
private void 显示子窗体ToolStripMenuItem_Click(object sender, EventArgs e){ SubForm1 sb1 = new SubForm1(); sb1.Show(); sb1.MdiParent = this; SubForm2 sb2 = new SubForm2(); sb2.Show(); sb2.MdiParent = this;}private void 横向排列Too原创 2020-09-14 16:04:38 · 1196 阅读 · 1 评论 -
C#将窗体文本输入框中的内容写入指定的存储位置
private void btnSave_Click(object sender, EventArgs e) { using (FileStream fsWrite = new FileStream(@"C:\Users\WanAkiko\Desktop\新建文本文档.txt", FileMode.OpenOrCreate, FileAccess.Write)) { string str = 文本输入框.Text.Trim(); ...原创 2020-09-14 13:08:39 · 1521 阅读 · 0 评论 -
C#输入IP地址并检查格式再进行分截取
using System;namespace CSharp三次课{ class Program { static void Main(string[] args) { bool shutdown = true; while (shutdown) { Console.Write("\n请输入一个IP地址:"); strin原创 2020-09-10 14:05:51 · 647 阅读 · 0 评论 -
C#相邻两数组元素同步长交换
using System;using System.Collections;using System.Collections.Generic;namespace OOP{class Program{static void Main(string[] args){int[] chIndex = new int[] { 1, 2, 3, 4, 5, 6 };for (int i = 0; i <= 4; i += 2){int temp = chIndex[i];chIndex[原创 2020-09-10 11:13:12 · 445 阅读 · 0 评论 -
C#猴子吃桃逆向反推第一天的桃子数
using System;namespace CSharp二次课_课后_{ class Program { static void Main(string[] args) { int sum = 1; for (int i = 9; i > 0; i--) { sum = (sum + 1) * 2; Consol原创 2020-09-09 17:52:05 · 380 阅读 · 0 评论 -
C#求两个数的公约数(公因数)和公倍数
using System;namespace CSharp{ class Program { static void Main(string[] args) { Console.Write("请输入第一个数:"); int num01 = int.Parse(Console.ReadLine()); Console.Write("请输入第二个数:"); int原创 2020-09-09 17:27:58 · 1097 阅读 · 0 评论 -
C#接收字符串输入并逐个判断字符串元素的形式
using System;namespace CSharp{class Program{static void Main(string[] args){Console.Write(“请输入一段字符:”);char[] cArr = Console.ReadLine().ToCharArray();for (int i = 0; i < cArr.Length; i++){if (cArr[i] >= 65 && cArr[i] <= 90){Con原创 2020-09-09 17:12:19 · 942 阅读 · 0 评论 -
C#里氏转换is & as关键字使用示例
using System;using System.Collections.Generic;namespace oop05_里式转换{ class Program { static void Main(string[] args) { // is使用示例 Person subStu = new Student(); // Student类继承自Person类 if (subStu原创 2020-09-03 19:02:50 · 278 阅读 · 0 评论 -
C#里氏转换练习(随机类型转换和对应方法调用)
using System;using System.Collections.Generic;namespace oop05_里式转换{ class Program { static void Main(string[] args) { Person[] per = new Person[10]; Random rd = new Random(); for (int i = 0; i原创 2020-09-03 18:55:54 · 188 阅读 · 0 评论 -
C#里氏转换(对象转型)
子类可以赋值给父类:即向上转型,子类对象可以调用父类的成员,但父类对象只能调用自己的成员。 向上转型:子类对象交给父类引用,父类引用指向子类对象。 Eg:Animal an = new Dog(); 若父类中装的是子类对象,则可将此父类强转为子类对象:即向下转型,父类引用决定可以调用什么,而子类对象决定具体做什.原创 2020-08-29 18:06:13 · 252 阅读 · 0 评论 -
C#判断字符串对象是否为空的几种方式
① 字符串对象有初始值且不为null时使用:object.Length() == 0 Tips:此方法效率最高但在使用时可能产生异常。② object == string.Empty 和 object == "" Tips:此两项方法前者的效率要略高于后者,但均逊于object.Length() == 0,使用时不会产生异常。③ 判断字符串对象是否存在以及是否为空:string.IsN原创 2020-08-16 16:25:48 · 7392 阅读 · 0 评论 -
C#保留两位小数输出的两种方式
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _37_Ex_Reserve2AndPrime { static void Main(string[] args) { #region 计算整形数组元素的平均值,保留两位小数输出 int[] intArr = {原创 2020-08-07 19:56:18 · 11410 阅读 · 0 评论 -
C#找出字符串数组中最长的元素
using DocumentFormat.OpenXml.Drawing.Charts;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _36_Ex_Function { static void Main(string[] args) { string[] NBA = { "张伯伦"原创 2020-08-07 18:49:03 · 1412 阅读 · 0 评论 -
C#输入两个数,数字2必须大于数字1,计算从数字1到数字2的和
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _35_Ex_Function { /// <summary> /// 方法练习 /// </summary> /// <param name="args"></param>原创 2020-08-04 22:03:59 · 411 阅读 · 0 评论 -
C#中 params 参数的使用
将实参列表中与动态参数数组类型一致的元素当做数组元素进行操作,参数数组必须是形参列表中的最后一个参数。using DocumentFormat.OpenXml.Drawing.Diagrams;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _34_ArgsParams { static void Main(string原创 2020-08-04 16:25:11 · 723 阅读 · 0 评论 -
C#中 ref 参数的使用
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _33_ArgsRef { static void Main(string[] args) { int num01 = 10, num02 = 20; Console.WriteLine("交换前:num01({0原创 2020-08-03 22:33:08 · 512 阅读 · 0 评论 -
C#使用 out 参数模拟 int.TryParse() 的功能实现
using DocumentFormat.OpenXml.Drawing.Charts;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _32_Ex_ArgsOut { static void Main(string[] args) { int result;原创 2020-08-03 18:54:55 · 679 阅读 · 0 评论 -
C#使用 out 参数模拟用户登录
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _31_Ex_ArgsOut { /// <summary> /// 使用out参数模拟用户登录 /// </summary> /// <param name="args"></param原创 2020-08-03 18:36:59 · 190 阅读 · 0 评论 -
C#中 out 参数的使用
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _31_ArgsOut { static void Main(string[] args) { int[] numArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // 当使用out参数接原创 2020-08-03 17:21:16 · 1706 阅读 · 0 评论 -
C#编写返回相同类型的值的方法(元素最值、总和、平均值)
using DocumentFormat.OpenXml.Spreadsheet;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _30_ArgsOut { static void Main(string[] args) { int[] numArr = { 1, 2, 3, 4,原创 2020-08-03 16:53:53 · 267 阅读 · 0 评论 -
C#数组元素冒泡、选择、插入排序
using DocumentFormat.OpenXml.Wordprocessing;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _28_ArrayElements { static void Main(string[] args) { Random rd = new Rand原创 2020-07-26 09:01:59 · 271 阅读 · 0 评论 -
C#数组元素顺序存入倒序输出
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _27_Ex_Array { static void Main(string[] args) { string[] letterArr = { "A", "B", "C", "D", "E", "F", "G" };原创 2020-07-26 07:45:25 · 4239 阅读 · 3 评论 -
C#循环为字符串数组元素添加竖线(末尾元素不添加)
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _27_Ex_Array { static void Main(string[] args) { string[] nameArr = { "老杨", "老苏", "老周", "老马", "老蒋", "老赵", "老吴", "老华" };原创 2020-07-19 17:36:24 · 562 阅读 · 0 评论 -
C#随机1~100之间的数组元素并输出最值、总和及平均值
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _26_Array { /// <summary> /// 数组 /// </summary> /// <param name="args"></param> sta原创 2020-07-19 17:11:16 · 1530 阅读 · 1 评论 -
C#枚举与结构的综合运用
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _25_Structure { /// <summary> /// 性别枚举 /// </summary> public enum EnumGender { 男, 女 } /// <原创 2020-07-19 12:33:35 · 169 阅读 · 0 评论 -
C#枚举和自定义登录状态
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ public enum QQstatus { OnLine, QMe, Leave, Busy, PleaseDoNotDisturb, Cloaking, OffLine } class _24_Ex_Enum { static void Main原创 2020-07-19 12:01:03 · 331 阅读 · 0 评论 -
C#详解枚举类型的定义和转换
定义枚举类型:using DocumentFormat.OpenXml.Office2010.Excel;using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ public enum QQStatus { // 枚举QQ状态:在线,Q我吧,离开,忙碌,请勿打扰,隐身,离线 OnLine, QMe, Leave, Bus原创 2020-07-19 11:29:46 · 1189 阅读 · 0 评论 -
C#随机数和三元表达式
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _21_TernaryExpression { static void Main(string[] args) { Random rd = new Random(); // 创建随机器 for (int i = 0原创 2020-07-18 15:57:53 · 132 阅读 · 0 评论 -
C#以string和int为例展示数据类型转换的三种方式
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _18_TypeConvertAndFunction { static void Main(string[] args) { /// /// int Convert.ToInt32(string value);原创 2020-07-17 19:21:32 · 400 阅读 · 0 评论 -
C#接收5个年龄和计算平均年龄
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _19_Ex_For { static void Main(string[] args) { int[] ageArr = new int[5]; // 定义年龄数组 int times = 1; // 定义计次标原创 2020-07-17 19:20:13 · 790 阅读 · 0 评论 -
C#输出从0开始累加到输入的目标数之和的式子
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _17_Ex_For { static void Main(string[] args) { Console.Write("请输入一个目标数:"); try {原创 2020-07-13 17:31:10 · 367 阅读 · 0 评论 -
C#使用foreach遍历数组元素
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _17_Ex_For { static void Main(string[] args) { Console.Write("请指定需要录入的学生个数:"); int stuCount = int.Parse(Con原创 2020-07-12 17:10:42 · 1158 阅读 · 0 评论 -
C#循环输出九九乘法表
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _17_Ex_For { static void Main(string[] args) { Console.WriteLine("输出普通九九乘法表"); for (int i = 1; i <= 9; i原创 2020-07-12 16:57:00 · 1636 阅读 · 0 评论 -
C#输出100~999之间的水仙花数
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _17_Ex_For { static void Main(string[] args) { // 正向for循环:编辑器输入for后再按两下Tab键补齐代码 // 逆向for循环:编辑器输入forr后再按两下Ta原创 2020-07-12 16:48:04 · 2110 阅读 · 0 评论