运算符与类型转换 mogondb简介
运算符与类型转换
1.运算符
(1)分类
算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符、其他运算符
>.算术运算符:
| 运算符 | 描述 |
|---|---|
| + | 把两个操作数相加 |
| - | 从第一个操作数中减去第二个操作数 |
| * | 把两个操作数相乘 |
| / | 分子除以分母 |
| % | 取模运算符,整除后的余数 |
| ++ | 自增运算符,整数值增加 1 |
| -- | 自减运算符,整数值减少 1 |
>.关系运算符:
| 运算符 | 描述 |
|---|---|
| == | 检查两个操作数的值是否相等,如果相等则条件为真。 |
| != | 检查两个操作数的值是否相等,如果不相等则条件为真。 |
| > | 检查左操作数的值是否大于右操作数的值,如果是则条件为真。 |
| < | 检查左操作数的值是否小于右操作数的值,如果是则条件为真。 |
| >= | 检查左操作数的值是否大于或等于右操作数的值,如果是则条件为真。 |
| <= | 检查左操作数的值是否小于或等于右操作数的值,如果是则条件为真。 |

using System;
namespace study
{
public class demo0_operator
{
static void Main(string[] args)
{
UserControl u1 = new UserControl("1", 2, 3);
UserControl u2 = new UserControl("1", 4, 5);
Console.WriteLine("hashcode of u1 is=" + u1.GetHashCode());
Console.WriteLine("hashcode of u2 is=" + u2.GetHashCode());
Console.WriteLine("u1==u2 is " + (u1 == u2));
//demo string
string s1 = "hello word";
string s2 = "hello word";
string s3 = "hello " + "word";
Console.WriteLine("hashcode of s1 is=" + s1.GetHashCode());
Console.WriteLine("hashcode of s2 is=" + s2.GetHashCode());
Console.WriteLine("hashcode of s3 is=" + s3.GetHashCode());
Console.WriteLine("s1==s2 is " + (s1 == s2));
Console.WriteLine("s1==s3 is " + (s1 == s3));
//运行结果如下:
// hashcode of u1 is=1062342447
// hashcode of u2 is=472133479
// u1==u2 is True
// hashcode of s1 is=-645689584
// hashcode of s2 is=-645689584
// hashcode of s3 is=-645689584
// s1==s2 is True
}
}
public class UserControl
{
public string id;
public int width;
public int height;
public UserControl(string id, int width, int height)
{
this.id = id;
this.width = width;
this.height = height;
}
public static bool operator ==(UserControl lhs, UserControl rhs)
{
return lhs.id == rhs.id;
}
public static bool operator !=(UserControl lhs, UserControl rhs)
{
return !(lhs == rhs);
}
public override bool Equals(object obj)
{
if (obj is UserControl) return false;
return this == (UserControl)obj;
}
public override int GetHashCode()
{
return this.ToString().GetHashCode();
}
public override string ToString()
{
return "控件id:" + this.id + "宽度" + this.width + ";高度:" + this.height;
}
}
}

>.逻辑运算符:
| 运算符 | 描述 |
|---|---|
| && | 称为逻辑与运算符。如果两个操作数都非零,则条件为真。 |
| || | 称为逻辑或运算符。如果两个操作数中有任意一个非零,则条件为真。 |
| ! | 称为逻辑非运算符。用来逆转操作数的逻辑状态。如果条件为真则逻辑非运算符将使其为假。 |
>.位运算符:
位运算符作用于位,并逐位执行操作。&、 | 和 ^ 的真值表如下所示
| p | q | p & q | p | q | p ^ q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 |
>.赋值运算符:
| 运算符 | 描述 |
|---|---|
| = | 简单的赋值运算符,把右边操作数的值赋给左边操作数 |
| += | 加且赋值运算符,把右边操作数加上左边操作数的结果赋值给左边操作数 |
| -= | 减且赋值运算符,把左边操作数减去右边操作数的结果赋值给左边操作数 |
| *= | 乘且赋值运算符,把右边操作数乘以左边操作数的结果赋值给左边操作数 |
| /= | 除且赋值运算符,把左边操作数除以右边操作数的结果赋值给左边操作数 |
| %= | 求模且赋值运算符,求两个操作数的模赋值给左边操作数 |
| <<= | 左移且赋值运算符 |
| >>= | 右移且赋值运算符 |
| &= | 按位与且赋值运算符 |
| ^= | 按位异或且赋值运算符 |
| |= | 按位或且赋值运算符 |
>.其他运算符:
| 运算符 | 描述 |
|---|---|
| sizeof() | 返回数据类型的大小。 |
| typeof() | 返回 class 的类型。 |
| & | 返回变量的地址。 |
| * | 变量的指针。 |
| ? : | 条件表达式 |
| is | 判断对象是否为某一类型。 |
| as | 强制转换,即使转换失败也不会抛出异常。 |

using System;
namespace study
{
public class demo2_reflection
{
private string currentType = typeof(demo2_reflection).ToString();
private string value;
public demo2_reflection(string value)
{
this.value = value;
}
public void showName()
{
Console.WriteLine("currentType is " + currentType);
Console.WriteLine("value=" + this.value);
}
static void Main(string[] args)
{
Type t = Type.GetType("study.demo2_reflection");
Console.WriteLine("type of t is "+t.GetType().ToString());
Object[] constructParms = new object[] {"hello word"}; //构造器参数
demo2_reflection obj = (demo2_reflection)Activator.CreateInstance(t, constructParms);
obj.showName();
}
}
}

2.运算符优先级
| 类别 | 运算符 |
|---|---|
| 后缀 | () [] -> . ++ - - |
| 一元 | + - ! ~ ++ - - (type)* & sizeof |
| 乘除 | * / % |
| 加减 | + - |
| 移位 | << >> |
| 关系 | < <= > >= |
| 相等 | == != |
| 位与 AND | & |
| 位异或 XOR | ^ |
| 位或 OR | | |
| 逻辑与 AND | && |
| 逻辑或 OR | || |
| 条件 | ?: |
| 赋值 | = += -= *= /= %=>>= <<= &= ^= |= |
| 逗号 | , |
2.类型转换
C#里的类型转换
(1)隐式转换
从类型A到类型B的转换可以在所有情况下进行,执行转换的规则非常简单,可以让编译器执行转换。
隐式转换不需要做任何工作,也不需要另外编写代码。如将int型数据转换成double型数据:
int a = 10; double b = a;//隐式转换
(2)显式转换
从类型A到类型B的转换只能在某些情况下进行,转换规则比较复杂,应进行某种类型的额外处理。显式转换又叫强制类型转换,显式转换需要用户明确的指定转换类型。如将double类型数据转换成int类型数据:
double c = 10.5; int d = (int)c;//显示转换
(3)通过方法进行类型转换
| 序号 | 方法 & 描述 |
|---|---|
| 1 | ToBoolean 如果可能的话,把类型转换为布尔型。 |
| 2 | ToByte 把类型转换为字节类型。 |
| 3 | ToChar 如果可能的话,把类型转换为单个 Unicode 字符类型。 |
| 4 | ToDateTime 把类型(整数或字符串类型)转换为 日期-时间 结构。 |
| 5 | ToDecimal 把浮点型或整数类型转换为十进制类型。 |
| 6 | ToDouble 把类型转换为双精度浮点型。 |
| 7 | ToInt16 把类型转换为 16 位整数类型。 |
| 8 | ToInt32 把类型转换为 32 位整数类型。 |
| 9 | ToInt64 把类型转换为 64 位整数类型。 |
| 10 | ToSbyte 把类型转换为有符号字节类型。 |
| 11 | ToSingle 把类型转换为小浮点数类型。 |
| 12 | ToString 把类型转换为字符串类型。 |
| 13 | ToType 把类型转换为指定类型。 |
| 14 | ToUInt16 把类型转换为 16 位无符号整数类型。 |
| 15 | ToUInt32 把类型转换为 32 位无符号整数类型。 |
| 16 | ToUInt64 把类型转换为 64 位无符号整数类型。 |

using System;
namespace study
{
public static class typeConversion
{
public static string timeToString(DateTime value)
{
return value.ToString("yyyy-MM-dd HH:mm:ss fff");
}
public static string timeToStringEx(this DateTime value)
{
return value.ToString("yyyy-MM-dd HH:mm:ss fff");
}
static void Main(string[] args)
{
DateTime now=DateTime.Now;
Console.WriteLine("timeToString="+typeConversion.timeToString(now));
Console.WriteLine("timeToStringEx="+now.timeToStringEx());
}
}
}


using System;
namespace study
{
public class typeConversion
{
static IUserControl getInstance(string controlName)
{
switch (controlName)
{
case "TextBox":
return new User_TextBox();
case "Dropdown":
return new User_Dropdown();
default:
return new User_TextBox();
}
}
static void Main(string[] args)
{
IUserControl contorl1 = new User_TextBox();
IUserControl contorl2 = new User_Dropdown();
Console.WriteLine("type of contorl1" + contorl1.GetType().ToString());
Console.WriteLine("type of contorl2" + contorl2.GetType().ToString());
IUserControl contorl3 = (IUserControl)contorl2;
Console.WriteLine("type of contorl3" + contorl3.GetType().ToString());
IUserControl contorl4 = getInstance("TextBox");
IUserControl contorl5 = getInstance("Dropdown");
Console.WriteLine("type of contorl4" + contorl4.GetType().ToString());
Console.WriteLine("type of contorl5" + contorl5.GetType().ToString());
}
}
public interface IUserControl
{
void getControl();
void checkdata();
void resetControl();
}
public class User_TextBox : IUserControl
{
public void checkdata()
{
Console.WriteLine("checkdata is User_TextBox");
}
public void getControl()
{
Console.WriteLine("getControl is User_TextBox");
}
public void resetControl()
{
Console.WriteLine("resetControl is User_TextBox");
}
}
public class User_Dropdown : IUserControl
{
public void checkdata()
{
Console.WriteLine("checkdata is User_Dropdown");
}
public void getControl()
{
Console.WriteLine("getControl is User_Dropdown");
}
public void resetControl()
{
Console.WriteLine("resetControl is User_Dropdown");
}
}
}

mogondb简介
MongoDB是一款强大、灵活,且易扩展的通用型数据库,其包含以下设计特点
1.1易于使用
与关系型数据库不同的是,它没有table/rows/records,相反采用更为灵活的文档(document);另外不在预定义模式,即没有数据类型、长度的限制,文档的key跟value不再受这些约束,即添加、删除更容易
1.2易于扩展
MongoDB采用横向扩展,即横向扩展机器。顺带提一下,纵向扩展是加大单机的配置,但始终会出现单机负载不了业务的时候。那横向扩展只需要向集群添加新机器,Mogondb就会自动将现有数据向新服务器传送
1.3丰富的功能
处理能够创建、读取、更新、删除以外,还提供其他不断扩展的功能:索引、聚合、特殊的集合类型(如某个时刻过期的sesssion、也支持固定大小的集合,用于保存近期的数据,如日志)、文件存储
但mongodb并不具备存在于关系型数据中的一些功能,如:jon和复杂的事务,因为在分布式的系统中这两个功能难以高效的实现
运算符与类型转换 mogondb简介的更多相关文章
- Python教程(2.3)——运算符和类型转换
Python里有很多运算符(operator),这节就让我们来详细学一学. 注意:本文没有特别说明的地方,只考虑bool.int.float三种类型.例如"两边操作数类型相同时,得到的结果为 ...
- [C++ Primer] : 第14章: 重载运算符与类型转换
基本概念 重载运算符是具有特殊名字的函数: 它们的名字由关键字operator和其后要定义的运算符号共同组成. 重载运算符函数的参数数量与该运算符作用的运算对象数量一样多. 对于二元运算符来说, 左侧 ...
- 【C++】C++中重载运算符和类型转换
输入输出运算符 输入输出运算符 输入输出运算符 算术和关系运算符 相等运算符 关系运算符 赋值运算符 复合赋值运算符 下标运算符 递增和递减运算符 成员访问运算符 函数调用运算符 lambda是函数对 ...
- C# 篇基础知识2——运算符、类型转换、流程控制、枚举、结构体和数组、函数
1.运算符.类型转换 计算某年y某月m某日d是周几的基姆拉尔森公式公式:int week = (d + 2*m + 3*(m + 1)/5 + y + y/4 - y/100 + y/400 + 1) ...
- # c++运算符重载之 前置++, 后置++, 负号运算符, 类型转换函数, 以及输入输出运算符
c++运算符重载之 前置++, 后置++, 负号运算符, 类型转换函数, 以及输入输出运算符 标签(空格分隔): c++ 前言 我在c++学习的过程中, 对这几个不太常见的运算符重载不太会写.出现了很 ...
- python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- 前端JavaScript(1) --Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- C++ Primer : : 第十四章 : 重载运算符与类型转换之类型转换运算符和重载匹配
类型转换运算符 class SmallInt { public: SmallInt(int i = 0) : val(i) { if (i < 0 || i > 255) throw st ...
- HTML 运算符、类型转换
1.类型转换: 分为自动转换和强制转换,一般用强制转换. 其他类型转换为整数:parseInt(): 其他类型转换为小数:parseFloat(): 判断是否是一个合法的数字类型:isNaN(): 是 ...
随机推荐
- struts2中关于jsp页面向action传值出现乱码问题
在JSP页面输入中文并传给后台的时候,常常会出现乱码问题,产生乱码的原因:java在进行传值的时候,默认用的是iso-8859-1的编码形式进行传输,而我们jsp页面常用的则是utf-8的编码形式.所 ...
- 关于inet_ntop、inet_pton中的n和p分别代表的意义
函数名中的p和n非别代表表达(presentation)和数值(numeric).地址的表达格式通常是ASCII字符串,数值格式则是存放到套接字地址结构中的二进制值. 参考自:https://blog ...
- mysql5.7zip安装
一.下载mysql zip文件 二.解压.(我的目录A:\mysql\mysql-5.7.23-winx64) 三.配置环境变量 Path后面追加%A:\mysql\mysql-5.7.23-wi ...
- 如何将数据放入下拉框List值
最近在做下拉框,里面放入值大概有这几种 //仓库业务类型 第一种 model.addAttribute("warehouseBizTypeList", basePropertySe ...
- 【02】sass更新的方法
[02]更新的方法 gem install sass **
- 大数据学习——redis安装
用源码工程来编译安装 / 到官网下载最新stable版 / 解压源码并进入目录 .tar.gz -C ./redis-src/ / make 如果报错提示缺少gcc,则安装gcc : yum inst ...
- NYOJ760-See LCS again,有技巧的暴力!
See LCS again 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 There are A, B two sequences, the number of ele ...
- BZOJ 3175: [Tjoi2013]攻击装置
捉水题真是捉上瘾了TUT Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2),(x-2,y- ...
- java多线程调试
1. 多线程调试 https://blog.csdn.net/bramzhu/article/details/52367052 https://www.jb51.net/article/129632. ...
- 1597: [Usaco2008 Mar]土地购买 [ dp+斜率优化 ] 未完
传送门 1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1979 Solved: 705[Subm ...