using ClassLibrary1;//引入的外界命名空间
using ModbusDemo;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApp1//Prgram类所在的命名空间
{
class Program//类名称 C#中允许一个类文件对应多个类
{
delegate int NumberChanger(int n);
static void Main(string[] args)//方法
{
byte[] a = new byte[10];//程序语句
//a[0] = -127;
Console.WriteLine(a[0]);
int ccc = a[0] & 0xff;
Console.WriteLine(ccc);
//byte b = -127;//
#region 数据类型
//Person p = new Person("aaa");
//p.SayHello();
//Rectangle rectangle = new Rectangle();
//rectangle.Acceptdetails();
//rectangle.Area();
//rectangle.DisPlay();
//Console.WriteLine("Size of int:Byte{0},Short{1},int{2},long{3},double{4},float{5}",
// sizeof(Byte),
// sizeof(short),
// sizeof(int),
// sizeof(long),
// sizeof(double),
// sizeof(float)
// );
//当上面代码被编译和执行时,它会产生下列结果
//引用类型(Reference types)
//引用类型不包含存储在变量中的实际数据,但它们包含对变量的引用
//换句话说,它们指的是一个内存位置.使用多个变量时,引用类型可以指向一个内存位置。如果内存位置的数据由一个变量改变
//其他变量会自动反映这种值的变化。内置的引用类型有:object string 和dynamic
//对象Object类型
//对象(Object)类型是C#通用系统(Common Type System -CTS)中所有数据类型的终极基类。Object是System.Object类的别名
//所以对象(Object)类型可以被分配任何其他类型(值类型、引用类型、预定义类型或用户自定义类型)的值。但是,在分配值之前
//需要先进行类型转换
//当一个值类型转换为对象类型时,则被成为装箱。另一方面,当一个对象转换为值类型,成为拆箱
//Console.ReadLine();
object obj;
obj = 100;//这是装箱
//int i = (int)obj;
//Console.WriteLine("{0},{1}",obj,i);
//动态(Dynamic)类型
//您可以存储任何类型的值在动态数据类型变量中。这些变量的类型检查是在运行时发生的
//声明动态类型的语法
//dynamic a = 100;
//动态类型与对象类型相似,但是对象类型变量的类型检查在编译时发生的,而动态类型的类型检查实在运行时发生的
//字符串(string)类型
/*字符串stirng类型 允许您给变量分配任何字符串值。字符串(Stirng)类型是System.String类的别名
它是从对象(Object)类型派生的。字符串(String)类型的值可以通过两种形式进行分配:引号和@引号
*/
string str = "runoob.com";
//一个引号字符串
str = @"runoob.com";
str = @"runoob.com";
//C#string字符串的前面可以加@(逐字字符串)将转义字符(\)当作普通字符对待,比如:
string strs = @"C\Windows";
//等价于
string strss = "C:\\Windows";
//@字符串可以任意换行,换行符及缩进空格都计算在字符串长度之内
string strsss = @"<script type=""text.javascript"">
<!--
-->
<script>
";
//用户自定义引用类型有:class interface或delegate.我们将在以后的章节中讨论这些类型
//指针类型(Pointer types)
//指针类型变量存储另一种类型的内存地址。C#中的指针与C或C++中的指针有相同的功能。
//申明指针类型的语法:
//type* identifier
//例如:
//char* cptr;
//int* iptr;
//char* cptr;
//我们将在章节"不安全的代码"中讨论指针类型
#endregion
#region 类型转换
//TypeConversionApplication t = new TypeConversionApplication();
//t.Test();
//t.TestType();
//t.Instancecase();
//t.AcceptUserValue();
//Contants contants = new Contants(5,5);
//contants.NewLine();
//contants.SayHelloWorld();
//contants.TestContants();
#endregion
//当上面代码被编译和执行时,产生下列结果
/*
x = 5,y = 5
c1 = 5,c2 = 10
*/
#region 运算符
OperatorApp o = new OperatorApp();
//o.OperatorStart();
//o.Assignment();
//o.LogicAssign();
//o.MoveOperator();
//o.AssginOperator();
//o.OperatorPrior();
#endregion
#region 判断
//Judge j = new Judge();
//int result = j.Jc(Convert.ToInt16(Console.ReadLine()));
//Console.WriteLine("result is {0}",result);
#endregion
#region 循环
//Cycle cycle = new Cycle();
//cycle.Test();
#endregion
#region 方法
//局部变量定义
//int ae = 100;
//int be = 200;
//int ret;
//FunctionDemo functionDemo = new FunctionDemo();
//ret =functionDemo.FindMax(ae,be);
//Console.WriteLine("最大值是:{0}",ret);
// ret= functionDemo.factorial(6);
//Console.WriteLine("6的阶乘是{0}",ret);
//ret = functionDemo.factorial(7);
//Console.WriteLine("7的阶乘是{0}",ret);
//ret = functionDemo.factorial(8);
//Console.WriteLine("8的阶乘是{0}",ret);
//Console.WriteLine("在交换之前ae的值{0}",ae);
//Console.WriteLine("在交换之前ae的值{0}", be);
functionDemo.swap(ae, be);
//functionDemo.swapRef(ref ae,ref be);
//Console.WriteLine("在交换之后ae的值{0}", ae);
//Console.WriteLine("在交换之后ae的值{0}", be);
//Console.WriteLine("在方法调用之前,a的值{0}",ae);
//functionDemo.getValue(out ae);
//Console.WriteLine("在方法调用之后,a的值{0}",ae);
//int v, w;
/*调用函数来获取值*/
//functionDemo.getValues(out v,out w);
//Console.WriteLine("在方法调用之后,v的值:{0}",v);
//Console.WriteLine("在方法调用之后,w的值:{0}", w);
#endregion
#region 数组
//ClassLibrary1.Array array = new ClassLibrary1.Array();
//array.Init();
#endregion
#region 线程
//ThreadDemo threadDemo = new ThreadDemo();
//threadDemo.Start();
#endregion
#region Socket
//SocketDemo s = new SocketDemo();
//s.ServerListen();
//s.ClientStart();
#endregion
#region Love
//LoveShape l = new LoveShape();
//l.GetLoveSef();
#endregion
#region 类
//Box box1 = new Box();//声明Box1,类型为Box
//Box box2 = new Box();//声明Box2,类型为Box
//double volume = 0.0;
Box1详述
//box1.height = 5.0;
//box1.length = 6.0;
//box1.breadth = 7.0;
Box2详述
//box2.height = 10.0;
//box2.length = 12.0;
//box2.breadth = 13.0;
Box1的体积
//volume = box1.height * box1.length * box1.breadth;
//Console.WriteLine("Box1的体积:{0}",volume);
Box2的体积
//volume = box2.height * box2.length * box2.breadth;
//Console.WriteLine("Box2的体积:{0}",volume);
//Console.ReadKey();
//Line line = new Line(10.0);
//Console.WriteLine("线条的长度:{0}",line.getLength());
设置线条长度
//line.setLength(6.0);
//Console.WriteLine("线条的长度:{0}",line.getLength());
//Line line = new Line();
设置线条长度
//line.setLength(6.0);
//Console.WriteLine("线条的长度:{0}",line.getLength());
//LineDemo lineDemo = new LineDemo();
//lineDemo.length = 6.0;
//Console.WriteLine("线条的长度:{0}",lineDemo.length);
//StaticVar staticVar1 = new StaticVar();
//StaticVar staticVar2 = new StaticVar();
//staticVar1.count();
//staticVar1.count();
//staticVar1.count();
//staticVar1.count();
//staticVar2.count();
//staticVar2.count();
//staticVar2.count();
//staticVar2.count();
//Console.WriteLine("s1的变量:{0}", StaticVar.getNum());
//Console.WriteLine("s2的变量:{0}", StaticVar.getNum());
//Rectangle rectangle = new Rectangle();
//int area;
//rectangle.setWidth(5);
//rectangle.setHeight(7);
//area = rectangle.getArea();
打印对象面积
//Console.WriteLine("总面积:{0}",rectangle.getArea());
//Console.WriteLine("油漆总成本:${0}",rectangle.getCost(area));
#endregion
#region 委托
//NumberChanger nc1 = new NumberChanger(ClassLibrary1.Delegate.AddNum);
//nc1(25);
//Console.WriteLine("{0}", ClassLibrary1.Delegate.getNum());
#endregion
#region 继承
//Rectangle rect = new Rectangle(4.5,7.5);
//rect.setWidth(5);
//rect.setHeight(7);
// Console.WriteLine("总面积:{0}",rect.GetArea());
//Tabletop t = new Tabletop(4.5,7.5);
//t.Display();
//Console.ReadLine();
#endregion
#region 枚举
//int x = (int)EnumDemo.Day.Sun;
//int y = (int)EnumDemo.Day.Fri;
//Console.WriteLine("Sun = {0}",x);
//Console.WriteLine("Fri = {0}",y);
#endregion
#region 命名空间
//first_space.namespace_c1 fc = new first_space.namespace_c1();
//second_space.namespace_c1 sc = new second_space.namespace_c1();
//fc.func();
//sc.func();
#endregion
//Console.WriteLine(Convert.ToByte("63"));
#region 反射
//System.Reflection.MemberInfo memberInfo = typeof(MyClass);
//object[] attributes = memberInfo.GetCustomAttributes(true);
//for (int j = 0; j < attributes.Length; j++)
//{
// System.Console.WriteLine(attributes[i]);
//}
#endregion
#region 属性
创建一个新的Student对象
//PropertyDemo propertyDemo = new PropertyDemo();
设置studeng的code,name,age
//propertyDemo.Code = "001";
//propertyDemo.Name = "Zara";
//propertyDemo.Age = 9;
//Console.WriteLine("StudentInfo :{0}",propertyDemo);
增加年龄
//propertyDemo.Age += 1;
//Console.WriteLine("Student Info:{0}",propertyDemo);
#endregion
#region JsonConvert
//var algorithModel = new CustomerAlgorithmModel()
//{
// CustomerType = 1,
// DisplayName = "🐂",
// Report = new ReportModel()
// {
// TotalCustomerCount = 1000,
// TotalTradeCount = 50
// },
// CustomerIDHash = new System.Collections.Generic.HashSet<int>(Enumerable.Range(1, 500000))
//};
//var json = JsonConvert.SerializeObject(algorithModel);
//File.WriteAllText("1.txt",json,Encoding.UTF8);
//Console.WriteLine("写入完成!");
#endregion
#region Modbus
//string strHello = "Hello";
//byte[] buffer = new byte[strHello.Length];
//buffer = Encoding.UTF8.GetBytes(strHello);
// ModbusStudy.Test_0x10();
#endregion
#region 数据处理浮点数设置小数后位数
/*常用简单的有四种方法
这里介绍对浮点数处理,同样的对其他类型如双浮点数double int等数据类型处理方法思路差不多
使用数学函数集合Mathf运算符:Mathf.Round();//浮点数四舍五入取整,如果舍去位是数字5,不管个位数是
偶数还是奇数,将返回偶数
*/
//float aa = MathF.Round(2.4567f);//结果为2
//float bb = MathF.Round(2.5123f);//结果为2,小数位是5,个数位在2,3之间取偶数2
//float bbbb = MathF.Round(2.5123f);//结果为2,小数位是5,个数位在2,3之间取偶数2
//float cc = MathF.Round(3.4521f);//结果为3
//string data = "abcdefgh";
//string dataT = new string(data.ToCharArray().Reverse().ToArray());
//string dataTemp = string.Empty;
//char[] arr = data.ToCharArray();
//System.Array.Reverse(arr);
//dataTemp = new string(arr);
//NiXuClass n = new NiXuClass();
//n.NiXu("12345678");
//int iii = 0;
//while (true)
//{
// Console.WriteLine("<<左移位符号:空位补0,被移除的高位丢弃");
// Thread.Sleep(5000);
// Console.WriteLine(">>右移位符号:被移动的最高位是0,右移后,空缺位补0;最高位是1,最高位补1");
// Thread.Sleep(5000);
//}
#endregion
#region 逐字输出
//TimerStart timerStart = new TimerStart();
//timerStart.Start();
#endregion
#region 循环
//WhileDemo whileDemo = new WhileDemo();
//whileDemo.JiuJiuBiao();
//whileDemo.SanJiaoXing();
// whileDemo.LoveMe();
//whileDemo.IntSum();
//whileDemo.RenSheng();
//whileDemo.BreakDemo();
//whileDemo.ForDemo();
#endregion
#region 接口
//InterfaceImplementer interfaceImplementer = new InterfaceImplementer();
//interfaceImplementer.MethodToImplement();
//RegixDemo regixDemo = new RegixDemo();
//string strS = "A Thousand Splendid Suns";
//regixDemo.SKaiTou(strS,@"\bS\S*");
//Console.ReadKey();
#endregion
#region 多线程 70万个字卡死了 vs
//Thread th = Thread.CurrentThread;
//th.Name = "MainThread";
//ThreadState bbb = th.ThreadState;
//bool aaa = th.IsAlive;
//th.Abort();
//Console.WriteLine("This is {0}",th.Name);
//Console.ReadKey();
//ThreadStart childref = new ThreadStart(CallToChildThreads);
//Console.WriteLine("In Main:Creating the Child thread");
//Thread childThread = new Thread(childref);
//childThread.Start();
//Console.ReadKey();
#endregion
/*
0x20
你怎么数的
怎么还0x19!
改改解析部分
*/
}
public static void CallToChildThreads()
{
Console.WriteLine("Child thread starts");
//线程暂停5000毫秒
Console.WriteLine("Child Thread Paused for {0}");
}
}
public class LineDemo //类名称
{
public double length { get; set; }
public LineDemo()
{
Console.WriteLine(“对象已创建”);
}
~LineDemo()//析构函数
{
Console.WriteLine(“对象已删除”);
}
}
#region 打印
//private int printShow(string url)
//{
// int isOK = 0;
// PDFFile file = PDFFile.Open(url);
// PrinterSettings setting = new PrinterSettings();
// System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
// settings.PrinterName = "NPI84FFAF(HP LaserJet MFP M436)";//打印机名称
// settings.PrintToFile = false;
// //设置纸张大小(可以不设置,取默认设置)3.90in,8.65 in
// PaperSize ps = new PaperSize("test",4,9);
// ps.RawKind = 9;//如果是自定义智障,就要大于118,(A4值为9,详细纸张类型与值的对照请看)
// O2S.Components.PDFRender4NET.Printing.PDFPrintSettings pdfPrintSettings = new O2S.Components.PDFRender4NET.Printing.PDFPrintSettings(settings);
// pdfPrintSettings.PaperSize = ps;
// pdfPrintSetting.PageScaling = O2S.Components.PDFRender4NET.Printing.PageScaling.FitToPrinterMarginsProportional;
// pdfPrintSettings.PrinterSettings.Copies = 1;
// try
// {
// file.Print(pdfPrintSettings);
// isOk = 1;
// }
// catch (Exception)
// {
// file.Dispose();
// throw;
// }
// return isok;
//}
#endregion
}