表达式树练习实践:C# 运算符

在 C# 中,算术运算符,有以下类型

  • 算术运算符
  • 关系运算符
  • 逻辑运算符
  • 位运算符
  • 赋值运算符
  • 其他运算符

这些运算符根据参数的多少,可以分作一元运算符、二元运算符、三元运算符。本文将围绕这些运算符,演示如何使用表达式树进行操作。

对于一元运算符和二元运算符的 Expression 的子类型如下:

UnaryExpression; //一元运算表达式
BinaryExpression; //二元运算表达式

一,算术运算符

运算符 描述
+ 把两个操作数相加
- 从第一个操作数中减去第二个操作数
* 把两个操作数相乘
/ 分子除以分母
% 取模运算符,整除后的余数
++ 自增运算符,整数值增加 1
-- 自减运算符,整数值减少 1

+ 与 Add()

正常代码

            int a;
int b;
a = 100;
b = 200;
var ab = a + b;
Console.WriteLine(ab);

使用表达式树构建

            ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // ab = a + b
BinaryExpression ab = Expression.Add(a, b); // 打印 a + b 的值
MethodCallExpression method = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), ab); Expression<Action<int, int>> lambda = Expression.Lambda<Action<int, int>>(method, a, b);
lambda.Compile()(100, 200); Console.ReadKey();

如果想复杂一些,使用 来执行:

            ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // 别忘记了赋值
BinaryExpression aa = Expression.Assign(a, Expression.Constant(100, typeof(int)));
BinaryExpression bb = Expression.Assign(b, Expression.Constant(200, typeof(int))); // ab = a + b
BinaryExpression ab = Expression.Add(a, b); // 打印 a + b 的值
MethodCallExpression method = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), ab); // 以块的形式执行代码,相当于{ }
// 不需要纠结这里,后面会有详细说明,重点是上面
var call = Expression.Block(new ParameterExpression[] { a, b }, aa, bb, method);
Expression<Action> lambda = Expression.Lambda<Action>(call);
lambda.Compile()();

上面两个示例,是使用表达式树计算结果,然后还是使用表达式树打印结果。

前者依赖外界传入参数值,赋予 a、b,后者则全部使用表达式树赋值和运算。

那么,如何通过表达式树执行运算,获取执行结果呢?

            ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // ab = a + b
BinaryExpression ab = Expression.Add(a, b); Expression<Func<int, int, int>> lambda = Expression.Lambda<Func<int, int, int>>(ab, a, b);
int result = lambda.Compile()(100, 200); Console.WriteLine(result);
Console.ReadKey();

这些区别在于如何编写 Expression.Lambda()

另外,使用 AddChecked() 可以检查操作溢出。

- 与 Subtract()

与加法一致,此处不再赘述,SubtractChecked() 可以检查溢出。

a - b ,结果是 100 。

            ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // ab = a - b
BinaryExpression ab = Expression.Subtract(a, b); Expression<Func<int, int, int>> lambda = Expression.Lambda<Func<int, int, int>>(ab, a, b);
int result = lambda.Compile()(200, 100); Console.WriteLine(result);

乘除、取模

乘法

            // ab = a * b
BinaryExpression ab = Expression.Multiply(a, b);
// ab = 20000

除法

            // ab = a / b
BinaryExpression ab = Expression.Divide(a, b);
// ab = 2

取模(%)

            ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // ab = a % b
BinaryExpression ab = Expression.Modulo(a, b); Expression<Func<int, int, int>> lambda = Expression.Lambda<Func<int, int, int>>(ab, a, b);
int result = lambda.Compile()(200, 150);
// ab = 50
Console.WriteLine(result);
Console.ReadKey();

自增自减

自增自减有两种模型,一种是 x++ 或 x--,另一种是 ++x 或 --x

他们都是属于 UnaryExpression 类型。

算术运算符 表达式树 说明
x++ Expression.PostIncrementAssign() 后置
x-- Expression.PostDecrementAssign() 后置
++x Expression.PreIncrementAssign() 前置
--x Expression.PreDecrementAssign() 前置

巧记:Post 后置, Pre 前置;Increment 是加,Decrement是减;Assign与赋值有关(后面会说到);

x++x-- 的使用

            int a = 10;
int b = 10;
a++;
b--;
Console.WriteLine(a);
Console.WriteLine(b);
            // int a,b;
ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // a = 10,b = 10;
BinaryExpression setA = Expression.Assign(a, Expression.Constant(10));
BinaryExpression setB = Expression.Assign(b, Expression.Constant(10)); // a++
UnaryExpression aa = Expression.PostIncrementAssign(a); // b--
UnaryExpression bb = Expression.PostDecrementAssign(b); //Console.WriteLine(a);
//Console.WriteLine(b);
MethodCallExpression callA = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), a);
MethodCallExpression callB = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), b); BlockExpression block = Expression.Block(
new ParameterExpression[] { a, b },
setA,
setB,
aa,
bb,
callA,
callB
); Expression<Action> lambda = Expression.Lambda<Action>(block);
lambda.Compile()(); Console.ReadKey();

如果想把参数从外面传入,设置 a,b

            // int a,b;
ParameterExpression a = Expression.Variable(typeof(int), "a");
ParameterExpression b = Expression.Variable(typeof(int), "b"); // a++
UnaryExpression aa = Expression.PostIncrementAssign(a); // b--
UnaryExpression bb = Expression.PostDecrementAssign(b); //Console.WriteLine(a);
//Console.WriteLine(b);
MethodCallExpression callA = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), a);
MethodCallExpression callB = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), b); BlockExpression block = Expression.Block(
aa,
bb,
callA,
callB
); Expression<Action<int, int>> lambda = Expression.Lambda<Action<int, int>>(block, a, b);
lambda.Compile()(10, 10);
Console.ReadKey();

生成的表达式树如下

.Lambda #Lambda1<System.Action`2[System.Int32,System.Int32]>(
System.Int32 $a,
System.Int32 $b) {
.Block() {
$a++;
$b--;
.Call System.Console.WriteLine($a);
.Call System.Console.WriteLine($b)
}
}

为了理解一下 Expression.Block(),可以在这里学习一下(后面会说到 Block())。

            // int a,b;
ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b");
ParameterExpression c = Expression.Variable(typeof(int), "c"); BinaryExpression SetA = Expression.Assign(a, c);
BinaryExpression SetB = Expression.Assign(b, c);
// a++
UnaryExpression aa = Expression.PostIncrementAssign(a); // b--
UnaryExpression bb = Expression.PostDecrementAssign(b); //Console.WriteLine(a);
//Console.WriteLine(b);
MethodCallExpression callA = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), a);
MethodCallExpression callB = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), b); BlockExpression block = Expression.Block(
new ParameterExpression[] { a, b },
SetA,
SetB,
aa,
bb,
callA,
callB
); Expression<Action<int>> lambda = Expression.Lambda<Action<int>>(block, c);
lambda.Compile()(10); Console.ReadKey();

为什么这里要多加一个 c 呢?我们来看看生成的表达式树

.Lambda #Lambda1<System.Action`1[System.Int32]>(System.Int32 $c) {
.Block(
System.Int32 $a,
System.Int32 $b) {
$a = $c;
$b = $c;
$a++;
$b--;
.Call System.Console.WriteLine($a);
.Call System.Console.WriteLine($b)
}
}

观察一下下面代码生成的表达式树

            // int a,b;
ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // a++
UnaryExpression aa = Expression.PostIncrementAssign(a); // b--
UnaryExpression bb = Expression.PostDecrementAssign(b); //Console.WriteLine(a);
//Console.WriteLine(b);
MethodCallExpression callA = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), a);
MethodCallExpression callB = Expression.Call(null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }), b); BlockExpression block = Expression.Block(
new ParameterExpression[] { a, b },
aa,
bb,
callA,
callB
); Expression<Action<int, int>> lambda = Expression.Lambda<Action<int, int>>(block, a, b);
lambda.Compile()(10, 10);
Console.ReadKey();
.Lambda #Lambda1<System.Action`2[System.Int32,System.Int32]>(
System.Int32 $a,
System.Int32 $b) {
.Block(
System.Int32 $a,
System.Int32 $b) {
$a++;
$b--;
.Call System.Console.WriteLine($a);
.Call System.Console.WriteLine($b)
}
}

关于前置的自增自减,按照上面示例编写即可,但是需要注意的是, ++x 和 --x ,是“先运算后增/自减”。

二,关系运算符

==、!=、>、<、>=、<=

C# 中的关系运算符如下

运算符 描述
== 检查两个操作数的值是否相等,如果相等则条件为真。
!= 检查两个操作数的值是否相等,如果不相等则条件为真。
> 检查左操作数的值是否大于右操作数的值,如果是则条件为真。
< 检查左操作数的值是否小于右操作数的值,如果是则条件为真。
>= 检查左操作数的值是否大于或等于右操作数的值,如果是则条件为真。
<= 检查左操作数的值是否小于或等于右操作数的值,如果是则条件为真。

== 表示相等比较,如果是值类型和 string 类型,则比较值是否相同;如果是引用类型,则比较引用的地址是否相等。

其它的关系运算符则是仅比较值类型的大小。

实例代码

            int a = 21;
int b = 10;
Console.Write("a == b:");
Console.WriteLine(a == b); Console.Write("a < b :");
Console.WriteLine(a < b); Console.Write("a > b :");
Console.WriteLine(a > b); // 改变 a 和 b 的值
a = 5;
b = 20; Console.Write("a <= b:");
Console.WriteLine(a <= b); Console.Write("a >= b:");
Console.WriteLine(b >= a); Console.ReadKey();

使用表达式树实现

            // int a,b;
ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b"); // a = 21,b = 10;
BinaryExpression setA = Expression.Assign(a, Expression.Constant(21));
BinaryExpression setB = Expression.Assign(b, Expression.Constant(20)); // Console.Write("a == b:");
// Console.WriteLine(a == b);
MethodCallExpression call1 = Expression.Call(null,
typeof(Console).GetMethod("Write", new Type[] { typeof(string) }),
Expression.Constant("a == b:"));
MethodCallExpression call11 = Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.Equal(a, b)); // Console.Write("a < b :");
// Console.WriteLine(a < b);
MethodCallExpression call2 = Expression.Call(null,
typeof(Console).GetMethod("Write", new Type[] { typeof(string) }),
Expression.Constant("a < b :"));
MethodCallExpression call22 = Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.LessThan(a, b)); // Console.Write("a > b :");
// Console.WriteLine(a > b);
MethodCallExpression call3 = Expression.Call(null,
typeof(Console).GetMethod("Write", new Type[] { typeof(string) }),
Expression.Constant("a > b :"));
MethodCallExpression call33 = Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.GreaterThan(a, b)); // 改变 a 和 b 的值
// a = 5;
// b = 20;
BinaryExpression setAa = Expression.Assign(a, Expression.Constant(5));
BinaryExpression setBb = Expression.Assign(b, Expression.Constant(20)); // Console.Write("a <= b:");
// Console.WriteLine(a <= b);
MethodCallExpression call4 = Expression.Call(null,
typeof(Console).GetMethod("Write", new Type[] { typeof(string) }),
Expression.Constant("a <= b:"));
MethodCallExpression call44 = Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.LessThanOrEqual(a, b)); // Console.Write("a >= b:");
// Console.WriteLine(b >= a);
MethodCallExpression call5 = Expression.Call(null,
typeof(Console).GetMethod("Write", new Type[] { typeof(string) }),
Expression.Constant("a >= b:"));
MethodCallExpression call55 = Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.GreaterThanOrEqual(a, b)); BlockExpression block = Expression.Block(new ParameterExpression[] { a, b },
setA,
setB,
call1,
call11,
call2,
call22,
call3,
call33,
setAa,
setBb,
call4,
call44,
call5,
call55
); Expression<Action> lambda = Expression.Lambda<Action>(block);
lambda.Compile()();
Console.ReadKey();

生成的表达式树如下

.Lambda #Lambda1<System.Action>() {
.Block(
System.Int32 $a,
System.Int32 $b) {
$a = 21;
$b = 20;
.Call System.Console.Write("a == b:");
.Call System.Console.WriteLine($a == $b);
.Call System.Console.Write("a < b :");
.Call System.Console.WriteLine($a < $b);
.Call System.Console.Write("a > b :");
.Call System.Console.WriteLine($a > $b);
$a = 5;
$b = 20;
.Call System.Console.Write("a <= b:");
.Call System.Console.WriteLine($a <= $b);
.Call System.Console.Write("a >= b:");
.Call System.Console.WriteLine($a >= $b)
}
}

三,逻辑运算符

&&、||、!

运算符 描述
&& 称为逻辑与运算符。如果两个操作数都非零,则条件为真。
|| 称为逻辑或运算符。如果两个操作数中有任意一个非零,则条件为真。
! 称为逻辑非运算符。用来逆转操作数的逻辑状态。如果条件为真则逻辑非运算符将使其为假。

逻辑运算符的运行,结果是 true 或 false。

逻辑运算符 表达式树
&& Expression.AndAlso()
|| Expression.OrElse()
Expression.Not()
            int a = 10;
int b = 11; Console.Write("[a == b && a > b]:");
Console.WriteLine(a == b && a > b); Console.Write("[a > b || a == b]:");
Console.WriteLine(a > b || a == b); Console.Write("[!(a == b)]:");
Console.WriteLine(!(a == b));
Console.ReadKey();

使用表达式树编写

            //int a = 10;
//int b = 11;
ParameterExpression a = Expression.Parameter(typeof(int), "a");
ParameterExpression b = Expression.Parameter(typeof(int), "b");
BinaryExpression setA = Expression.Assign(a, Expression.Constant(10));
BinaryExpression setB = Expression.Assign(b, Expression.Constant(11)); //Console.Write("[a == b && a > b]:");
//Console.WriteLine(a == b && a > b);
MethodCallExpression call1 = Expression.Call(null, typeof(Console).GetMethod("Write", new Type[] { typeof(string) }), Expression.Constant("[a == b && a > b]:")); MethodCallExpression call2 = Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.AndAlso(Expression.Equal(a, b), Expression.GreaterThan(a, b))
); //Console.Write("[a > b || a == b]:");
//Console.WriteLine(a > b || a == b);
MethodCallExpression call3 = Expression.Call(null, typeof(Console).GetMethod("Write", new Type[] { typeof(string) }), Expression.Constant("[a > b || a == b]:"));
MethodCallExpression call4 = Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.OrElse(Expression.Equal(a, b), Expression.GreaterThan(a, b))
); //Console.Write("[!(a == b)]:");
//Console.WriteLine(!(a == b));
MethodCallExpression call5 = Expression.Call(null, typeof(Console).GetMethod("Write", new Type[] { typeof(string) }), Expression.Constant("[!(a == b)]:"));
MethodCallExpression call6 = Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(bool) }),
Expression.Not(Expression.Equal(a, b))
);
BlockExpression block = Expression.Block(
new ParameterExpression[] { a, b },
setA,
setB,
call1,
call2,
call3,
call4,
call5,
call6
); Expression<Action> lambda = Expression.Lambda<Action>(block);
lambda.Compile()();
Console.ReadKey();

生成的表达式树如下

.Lambda #Lambda1<System.Action>() {
.Block(
System.Int32 $a,
System.Int32 $b) {
$a = 10;
$b = 11;
.Call System.Console.Write("[a == b && a > b]:");
.Call System.Console.WriteLine($a == $b && $a > $b);
.Call System.Console.Write("[a > b || a == b]:");
.Call System.Console.WriteLine($a == $b || $a > $b);
.Call System.Console.Write("[!(a == b)]:");
.Call System.Console.WriteLine(!($a == $b))
}
}

四,位运算符

&、|、^、~、<<、>>

运算符 描述 实例
& 如果同时存在于两个操作数中,二进制 AND 运算符复制一位到结果中。 (A & B) 将得到 12,即为 0000 1100
| 如果存在于任一操作数中,二进制 OR 运算符复制一位到结果中。 (A | B) 将得到 61,即为 0011 1101
^ 如果存在于其中一个操作数中但不同时存在于两个操作数中,二进制异或运算符复制一位到结果中。 (A ^ B) 将得到 49,即为 0011 0001
~ 按位取反运算符是一元运算符,具有"翻转"位效果,即0变成1,1变成0,包括符号位。 (~A ) 将得到 -61,即为 1100 0011,一个有符号二进制数的补码形式。
<< 二进制左移运算符。左操作数的值向左移动右操作数指定的位数。 A << 2 将得到 240,即为 1111 0000
>> 二进制右移运算符。左操作数的值向右移动右操作数指定的位数。 A >> 2 将得到 15,即为 0000 1111

限于篇幅,就写示例了。

位运算符 表达式树
& Expression.Add(Expression left, Expression right)
| Expression.Or(Expression left, Expression right)
^ Expression.ExclusiveOr(Expression expression)
~ Expression.OnesComplement( Expression expression)
<< Expression.LeftShift(Expression left, Expression right)
>> Expression.RightShift(Expression left, Expression right)

五,赋值运算符

运算符 描述 实例
= 简单的赋值运算符,把右边操作数的值赋给左边操作数 C = A + B 将把 A + B 的值赋给 C
+= 加且赋值运算符,把右边操作数加上左边操作数的结果赋值给左边操作数 C += A 相当于 C = C + A
-= 减且赋值运算符,把左边操作数减去右边操作数的结果赋值给左边操作数 C -= A 相当于 C = C - A
*= 乘且赋值运算符,把右边操作数乘以左边操作数的结果赋值给左边操作数 C *= A 相当于 C = C * A
/= 除且赋值运算符,把左边操作数除以右边操作数的结果赋值给左边操作数 C /= A 相当于 C = C / A
%= 求模且赋值运算符,求两个操作数的模赋值给左边操作数 C %= A 相当于 C = C % A
<<= 左移且赋值运算符 C <<= 2 等同于 C = C << 2
>>= 右移且赋值运算符 C >>= 2 等同于 C = C >> 2
&= 按位与且赋值运算符 C &= 2 等同于 C = C & 2
^= 按位异或且赋值运算符 C ^= 2 等同于 C = C ^ 2
|= 按位或且赋值运算符 C |= 2 等同于 C = C | 2

限于篇幅,请自行领略... ...

运算符 表达式树
= Expression.Assign
+= Expression.AddAssign
-= Expression.SubtractAssign
*= Expression.MultiplyAssign
/= Expression.DivideAssign
%= Expression.ModuloAssign
<<= Expression.LeftShiftAssign
>>= Expression.RightShiftAssign
&= Expression.AndAssign
^= Expression.ExclusiveOrAssign
|= Expression.OrAssign

^= ,注意有两种意思一种是位运算符的异或(ExclusiveOrAssign),一种是算术运算符的幂运算(PowerAssign)

六,其他运算符

运算符 描述 实例
sizeof() 返回数据类型的大小。 sizeof(int),将返回 4.
typeof() 返回 class 的类型。 typeof(StreamReader);
& 返回变量的地址。 &a; 将得到变量的实际地址。
* 变量的指针。 *a; 将指向一个变量。
? : 条件表达式 如果条件为真 ? 则为 X : 否则为 Y
is 判断对象是否为某一类型。 If( Ford is Car) // 检查 Ford 是否是 Car 类的一个对象。
as 强制转换,即使转换失败也不会抛出异常。 Object obj = new StringReader("Hello"); StringReader r = obj as StringReader;

表达式树里面我没有找到这些运算符的如何编写,如果你找到了,欢迎告诉我。。。

表达式树练习实践:C# 五类运算符的表达式树表达的更多相关文章

  1. 表达式树练习实践:C#判断语句

    目录 表达式树练习实践:C#判断语句 if if...else switch ?? 和 ?: 表达式树练习实践:C#判断语句 判断语句 C# 提供了以下类型的判断语句: 语句 描述 if 一个 if ...

  2. javascript运算符与表达式

    表达式 表达式是关键字.运算符.变量以及文字的组合,用来生成字符串.数字或对象.一个表达式可以完成计算.处理字符.调用函数.或者验证数据等操作. 表达式的值是表达式运算的结果,常量表达式的值就是常量本 ...

  3. C语言---程序的一般形式、数据类型、常量变量、运算符、表达式、格式化输入输出

    1. 程序的一般形式 (1)注释 ① 分类:单行注释( // ): 注释一行.多行注释( /**/ ): 在这个区间内,都属于多行注释,可以换行. ② 作用:提示代码的作用,提示思路   不写注释的后 ...

  4. 第十五节:Expression表达式目录树(与委托的区别、自行拼接、总结几类实例间的拷贝)

    一. 基本介绍 回忆: 最早接触到表达式目录树(Expression)可能要追溯到几年前使用EF早期的时候,发现where方法里的参数是Expression<Func<T,bool> ...

  5. 表达式树练习实践:C#值类型、引用类型、泛型、集合、调用函数

    目录 表达式树练习实践:C#值类型.引用类型.泛型.集合.调用函数 一,定义变量 二,访问变量/类型的属性字段和方法 1. 访问属性 2. 调用函数 三,实例化引用类型 四,实例化泛型类型于调用 五, ...

  6. 表达式树练习实践:C# 循环与循环控制

    目录 表达式树练习实践:C# 循环 LabelTarget for / while 循环 无限循环 最简单的循环 多次循环 break 和 continue 一起 表达式树练习实践:C# 循环 C# ...

  7. 01-Java基础知识:数据类型与变量、标识符、运算符、表达式

    Java基础知识:数据类型与变量.标识符.运算符.表达式 一.数据类型 Java定义了基本数据类型.引用数据类型.自定义类型. 八种基本数据类型:byte (1). short (2).  int ( ...

  8. java与.net比较学习系列(4) 运算符和表达式

    上一篇总结了java的数据类型,得到了冰麟轻武等兄弟的支持,他们提出并补充了非常好的建议,在这里向他们表示感谢.在后面的文章中,我会尽力写得更准确和更完善的,加油! 另外,因为C#是在java之后,也 ...

  9. Python第二天 变量 运算符与表达式 input()与raw_input()区别 字符编码 python转义符 字符串格式化 format函数字符串格式化 帮助

    Python第二天  变量  运算符与表达式  input()与raw_input()区别  字符编码  python转义符  字符串格式化  format函数字符串格式化  帮助 目录 Pychar ...

随机推荐

  1. JWT+Interceptor实现无状态登录和鉴权

    无状态登录原理 先提一下啥是有状态登录 单台tomcat的情况下:编码的流程如下 前端提交表单里用户的输入的账号密码 后台接受,查数据库, 在数据库中找到用户的信息后,把用户的信息存放到session ...

  2. DedeCMS 5.7 sp1远程文件包含漏洞(CVE-2015-4553)

    DedeCMS 5.7 sp1远程文件包含漏洞(CVE-2015-4553) 一.漏洞描述 该漏洞在/install/index.php(index.php.bak)文件中,漏洞起因是$$符号使用不当 ...

  3. 重学计算机组成原理(六)- 函数调用怎么突然Stack Overflow了!

    用Google搜异常信息,肯定都访问过Stack Overflow网站 全球最大的程序员问答网站,名字来自于一个常见的报错,就是栈溢出(stack overflow) 从函数调用开始,在计算机指令层面 ...

  4. thinkphp model 创建之后访问后的错误···

    解决:在php.ini里边先开启mysql的pdo扩展

  5. spring-boot-plus项目配置文件(四)

    spring-boot-plus项目配置文件 配置文件说明 配置说明 项目中配置文件主要使用yml格式 配置文件位置:spring-boot-plus\src\main\resources\confi ...

  6. 入门MySQL——用户与权限

    前言:  前面几篇文章为大家介绍了各种SQL语法的使用,本篇文章将主要介绍MySQL用户及权限相关知识,如果你不是DBA的话可能平时用的不多,但是了解下也是好处多多. 1.创建用户 官方推荐创建语法为 ...

  7. 运行所选代码生成器时出错:“值-1超出了可接受的[0,2147483647]范围。参数名称:value”

    在使用vs2019添加mvc控制器的时候 这已经是第二次遇到这个问题了.常言道,多喝热水,重启试试.有时候当应用工作不正常,重启也许能解决问题.但是程序员通常接触不到服务器系统权限.而运维人员和公司流 ...

  8. TortoiseGit的NetWork中的Enale proxy Server的作用

    NetWork中的Enale proxy Server 如果是局域网的代码管理需打勾: 如否是网路上的代码管理如:github是,要取消打勾: 否则回报:Couldn't resolve proxy ...

  9. Linux浏览创建文件

    pwd:打印当前工作目录(Print Working Directory) ls:列出文件和目录(List) - Ubuntu的清单默认有颜色区分:蓝色(目录).浅蓝色(链接文件).绿色(可执行文件) ...

  10. Spring学习之旅(十四)--缓存

    数据库的读写并发一直都是应用性能的瓶颈所在之一,针对改动频率很小的数据我们应该将他存放到缓存中,减少与数据库的交互. 启用对缓存的支持 Spring 对缓存的支持有两种方式: 注解驱动的缓存 XML ...