1、捕捉一只小可爱

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 捕捉一个小可爱
{
class Program
{
static void Main(string[] args)
{
bool b = true;
int number = ;
Console.WriteLine("请输入一个数字");
try
{
number = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("输入的内容不能转换为数字");
b = false;
}
if(b)
{
Console.WriteLine(number*);
}
Console.ReadKey();
}
}
}

2、判断闰年

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 判断闰年
{
class Program
{
static void Main(string[] args)
{
//判断闰年
Console.WriteLine("请输出需要判断的年份");
int year = Convert.ToInt32(Console.ReadLine());
bool b = year % == || year % == && year % != ;
Console.WriteLine(b);
Console.ReadKey();
}
}
}

3、冒泡排序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 冒泡排序
{
class Program
{
static void Main(string[] args)
{
int[] nums = { , , , , , , , , , };
for (int i = ; i < nums.Length - ; i++)
{
for (int j = ; j < nums.Length - - i; j++)
{
if (nums[j] > nums[j + ])
{
int temp = nums[j];
nums[j] = nums[j + ];
nums[j + ] = temp;
}
}
}
for (int i = ; i < nums.Length; i++)
{
Console.WriteLine(nums[i]);
}
Console.ReadKey();
}
}
}

4、多态

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 多态
{
class Program
{
static void Main(string[] args)
{
Aduck a = new Aduck();
Bduck b = new Bduck();
Cduck c = new Cduck();
Aduck[] adu = {a,b,c};
for (int i = ; i < adu.Length;i++ )
{
adu[i].say();
}
Console.ReadKey();
}
} public class Aduck
{
public virtual void say()
{
Console.WriteLine("");
}
} public class Bduck : Aduck
{
public override void say()
{
Console.WriteLine("");
}
} public class Cduck : Aduck
{
public override void say()
{
Console.WriteLine("");
}
}
}

5、switch-case

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace switch_case例子
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个考试成绩");
int number = Convert.ToInt32(Console.ReadLine());
//Console.WriteLine("输入的值/10取整数:{0}",number/10);
switch (number / )//可以将范围转换成一个定值
{
case ://执行代码一致可省略不写
case : Console.WriteLine("A");
break;
case : Console.WriteLine("B");
break;
case : Console.WriteLine("C");
break;
case : Console.WriteLine("D");
break;
default: Console.WriteLine("输入的成绩不及格");
break;
}
Console.ReadKey();
}
}
}

6、MD5加密

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks; namespace MD5加密
{
class Program
{
static void Main(string[] args)
{
string s = GetMD5("");
Console.WriteLine(s);
//double n = 12.345;
//Console.WriteLine(n.ToString("C"));
Console.ReadKey();
} public static string GetMD5(string str)
{
MD5 md5 = MD5.Create();
byte[] buffer = Encoding.Default.GetBytes(str);
byte[] MD5Buffer = md5.ComputeHash(buffer);
//return Encoding.GetEncoding("GBK").GetString(MD5Buffer);
string strNew = "";
for (int i = ; i < MD5Buffer.Length; i++)
{
strNew += MD5Buffer[i].ToString();
}
return strNew;
}
}
}

7、字符串

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 字符串
{
class Program
{
static void Main(string[] args)
{
//string s1 = "123";
//string s2 = "123";
string s = "a_b c=";
char[] chr = { ' ', '_', '=' };
string[] str = s.Split(chr, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(string.Join("", str));
Console.ReadKey();
}
}
}

8、模拟磁盘打开文件(面向对象继承)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics; namespace 模拟磁盘打开文件
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请选择要进入的磁盘");
string path = Console.ReadLine();
Console.WriteLine("请选择要进入的文件");
string fileName = Console.ReadLine();
//文件的全路径:path+fileName
FileFather ff = GetFile(fileName, path + fileName);
ff.OpenFile();
Console.ReadKey();
} public static FileFather GetFile(string fileName, string fullPath)
{
string extension = Path.GetExtension(fileName);
FileFather ff = null;
switch (extension)
{
case ".txt": ff = new TxtPath(fullPath);
break;
case ".jpg": ff = new JpgPath(fullPath);
break;
case ".wav": ff = new WavPath(fullPath);
break;
} return ff;
}
} public abstract class FileFather
{
//文件名
public string FileName
{
get;
set;
}
//定义一个构造函数,获取文件全路径
public FileFather(string fileName)
{
this.FileName = fileName;
}
//打开文件的抽象方法
public abstract void OpenFile();
} public class TxtPath : FileFather
{
//子类调用父类的构造函数,使用关键字base
public TxtPath(string fullPath)
: base(fullPath)
{ } public override void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FileName);
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
} public class JpgPath : FileFather
{
public JpgPath(string fullPath)
: base(fullPath)
{ } public override void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FileName);
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
} public class WavPath : FileFather
{
public WavPath(string fullPath)
: base(fullPath)
{ } public override void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FileName);
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
}
}

9、序列化和反序列化

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary; namespace 序列化和反序列化
{
class Program
{
static void Main(string[] args)
{
//要将p这个对象传递给电脑
person p = new person();
p.Name = "张三";
p.Gender = "男";
p.Age = ;
using (FileStream fswrite = new FileStream(@"C:\Users\CHD\Desktop\粘贴板.txt", FileMode.OpenOrCreate, FileAccess.Write))
{
//开始序列化
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fswrite, p);
}
Console.WriteLine("序列化成功");
Console.ReadKey(); //接收对方发过来的二进制,进行反序列化
//person p;
//using (FileStream fsread = new FileStream(@"C:\Users\CHD\Desktop\粘贴板.txt",FileMode.OpenOrCreate,FileAccess.Read))
//{
// BinaryFormatter bf = new BinaryFormatter();
// p = (person)bf.Deserialize(fsread);
//}
//Console.WriteLine(p.Name);
//Console.WriteLine(p.Gender);
//Console.WriteLine(p.Age);
//Console.ReadKey();
}
} [Serializable]
public class person
{
private string _name; public string Name
{
get { return _name; }
set { _name = value; }
} private string _gender; public string Gender
{
get { return _gender; }
set { _gender = value; }
} private int _age; public int Age
{
get { return _age; }
set { _age = value; }
}
}
}

10、为什么要使用委托

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 为什么要使用委托
{
class Program
{
public delegate string DelProStr(string str); static void Main(string[] args)
{
//三个需求
//1.将一个字符串数组每个元素都装换成大写
//2.将一个字符串数组每个元素都装换成小写
//3.将一个字符串数组每个元素两边都加上 双引号
string[] str = { "asCDeFg", "HIjklmN", "OpqrsT", "xyZ" };
//StrToLower(str);
ProStr(str, delegate(string name)
{
return name.ToUpper();
}); for (int i = ; i < str.Length; i++)
{
Console.WriteLine(str[i]);
}
Console.ReadKey();
} public static void ProStr(string[] str, DelProStr del)
{
for (int i = ; i < str.Length; i++)
{
str[i] = del(str[i]);
}
} //public static string StrToUpper(string str)
//{
// return str.ToUpper();
//} //public static string StrToLower(string str)
//{
// return str.ToLower();
//} //public static string StrSYH(string str)
//{
// return "\"" + str +"\"";
//} //public static void StrToUpper(string[] str)
//{
// for (int i = 0; i < str.Length; i++)
// {
// str[i] = str[i].ToUpper();
// }
//} //public static void StrToLower(string[] str)
//{
// for (int i = 0; i < str.Length; i++)
// {
// str[i] = str[i].ToLower();
// }
//} //public static void StrSYH(string[] str)
//{
// for (int i = 0; i < str.Length; i++)
// {
// str[i] = "\"" + str[i] + "\"";
// }
//}
}
}

11、Lamda表达式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lamda表达式
{
class Program
{
public delegate void DelOne();
public delegate void DelTwo(string name);
public delegate string DelThree(string name);
static void Main(string[] args)
{
//Lamda表达式 匿名函数的简单写法
DelOne del = () => { }; //delegate(){};
DelTwo del2 = (string name) => { };//delegate(string name) { };
DelThree del3 = (string name) => { return name; };//delegate(string name) { return name; }; List<int> list = new List<int>() { , , , , , };
list.RemoveAll(n => n > );
foreach (var item in list)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}

12、泛型委托

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 泛型委托
{
public delegate int DelCompare<T>(T t1, T t2); class Program
{
static void Main(string[] args)
{
int[] nums = { , , , , , };
int max = GetMax<int>(nums, Compare);
Console.WriteLine(max);
string[] names = { "qw", "asd", "zxc", "qsdc", "asdasdd", "qw" };
string name = GetMax<string>(names, (string s1, string s2) =>
{
return s1.Length - s2.Length;
});
Console.WriteLine(name);
Console.ReadKey();
} public static T GetMax<T>(T[] nums, DelCompare<T> del)
{
T max = nums[];
for (int i = ; i < nums.Length; i++)
{
if (del(max, nums[i]) < )
{
max = nums[i];
}
}
return max;
} public static int Compare(int n1, int n2)
{
return n1 - n2;
}
}
}

13、WinForm窗体传值

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 窗体传值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(MessMsg);
f2.Show();
} void MessMsg(string str)
{
label1.Text = str;
}
}
}
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 窗体传值
{ public delegate void DelText(string name); public partial class Form2 : Form
{
public DelText _del; public Form2(DelText del)
{
this._del = del;
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
_del(textBox1.Text);
}
}
}

.Net 经典案例的更多相关文章

  1. javascript的理解及经典案例

    js的简介: JavaScript是一种能让你的网页更加生动活泼的程式语言,也是目前网页中设计中最容易学又最方便的语言. 你可以利用JavaScript轻易的做出亲切的欢迎讯息.漂亮的数字钟.有广告效 ...

  2. jQuery基础的工厂函数以及定时器的经典案例

    1. jQuery的基本信息:  1.1 定义: jQuery是JavaScript的程序库之一,它是JavaScript对象和实用函数的封装, 1.2 作用: 许多使用JavaScript能实现的交 ...

  3. Linux运维之道(大量经典案例、问题分析,运维案头书,红帽推荐)

    Linux运维之道(大量经典案例.问题分析,运维案头书,红帽推荐) 丁明一 编   ISBN 978-7-121-21877-4 2014年1月出版 定价:69.00元 448页 16开 编辑推荐 1 ...

  4. 经典案例:那些让人赞不绝口的创新 HTML5 网站

    在过去的10年里,网页设计师使用 Flash.JavaScript 或其他复杂的软件和技术来创建网站.但现在你可以前所未有的快速.轻松地设计或创造互动的.有趣好看的网站.如何创建?答案是 HTML5 ...

  5. Altera OpenCL用于计算机领域的13个经典案例(转)

    英文出自:Streamcomputing 转自:http://www.csdn.net/article/2013-10-29/2817319-the-application-areas-opencl- ...

  6. php中foreach()函数与Array数组经典案例讲解

    //php中foreach()函数与Array数组经典案例讲解 function getVal($v) { return $v; //可以加任意检查代码,列入要求$v必须是数字,或过滤非法字符串等.} ...

  7. 阿里云资深DBA专家罗龙九:云数据库十大经典案例分析【转载】

    阿里云资深DBA专家罗龙九:云数据库十大经典案例分析 2016-07-21 06:33 本文已获阿里云授权发布,转载具体要求见文末 摘要:本文根据阿里云资深DBA专家罗龙九在首届阿里巴巴在线峰会的&l ...

  8. 经典案例之MouseJack

    引言:在昨天的文章<无线键鼠监听与劫持>中,我们提到今天会向您介绍一个无线键鼠的监听与劫持的经典案例,<MouseJack>:MouseJack能利用无线鼠标和键盘存在的一些问 ...

  9. HTML5 CSS3 经典案例:无插件拖拽上传图片 (支持预览与批量) (二)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/31513065 上一篇已经实现了这个项目的整体的HTML和CSS: HTML5 C ...

  10. Wolsey“强整数规划模型”经典案例之一单源固定费用网络流问题

    Wolsey“强整数规划模型”经典案例之一单源固定费用网络流问题 阅读本文可以理解什么是“强”整数规划模型. 单源固定费用网络流问题见文献[1]第13.4.1节(p229-231),是"强整 ...

随机推荐

  1. (转)js实现倒计时效果(年月日时分秒)

    原文链接:http://mengqing.org/archives/js-countdown.html 之前做的活动页面很多都用到了倒计时功能,所以整理下下次直接用.(用的是张鑫旭写的一个倒计时,稍作 ...

  2. HTML5画的简单时钟

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 设计模式课程 设计模式精讲 15-2 桥接模式Coding

    1 代码演练 1.1 代码演练1 1.2 代码演练2   1 代码演练 1.1 代码演练1 需求: 打印出从银行获取的账号类 优点: a 假如我只用用一个银行接口 去获取账号的内容,银行实现类要有定期 ...

  4. Flask - 请求扩展,钩子函数(Django的中间件) --> 请求前,中,后,

    例子1. 处理请求之前 @app.before_request 在请求之前,这个被装饰的函数会被执行 用户登录验证代码可以在这里写 @app.before_request def process_re ...

  5. php中$_REQUEST、$_POST、$_GET的区别和联系小结

    php中$_REQUEST.$_POST.$_GET的区别和联系小结 作者: 字体:[增加 减小] 类型:转载   php中有$_request与$_post.$_get用于接受表单数据,当时他们有何 ...

  6. 更改windows系统的快捷键方法

    众所周知,windows平台有很多快捷键使用非常的别扭. 现在提供windows 平台快捷键替换的绝佳软件:autohotkey 下载链接:http://ahkscript.org/ 中文帮助站点:h ...

  7. 今日份学习: springboot 用到的注解

    笔记 上回用到的所有注解 @Around @Aspect @Autowired @Bean @Configuration @RequestMapping @ResponseBody @RestCont ...

  8. 16核锐龙9延期真正原因 A饭热情太恐怖了

    锐龙9 3950X处理器是AMD发布的首款16核游戏处理器,原本会在9月上市,上周末AMD官方宣布它会延期2个月上市,会在11月跟锐龙Threadripper三代处理器一起上市. 锐龙9 3950X的 ...

  9. SpringMVC 转发、重定向

    转发.重定向到其它业务方法 @org.springframework.stereotype.Controller @RequestMapping("/userController" ...

  10. Raspbian设置静态ip

    Raspbian static ip 最近入手了树莓派4b,并更具官方教程安装了Raspbian.由于直接通过wifi连接,每次ip跳来跳去很不方便,于是便想着设置静态ip. 由于Raspbian本身 ...