1.String和string再c#中的有什么不同?

2.datatype  alias


1.String和string再c#中的有什么不同?

As others have noted, string is an alias for System.String. They compile to the same code, so at execution time there is no difference whatsoever. This is just one of the aliases in C#. The complete list is:

  • object: System.Object
  • string: System.String
  • bool: System.Boolean
  • byte: System.Byte
  • sbyte: System.SByte
  • short: System.Int16
  • ushort: System.UInt16
  • int: System.Int32
  • uint: System.UInt32
  • long: System.Int64
  • ulong: System.UInt64
  • float: System.Single
  • double: System.Double
  • decimal: System.Decimal
  • char: System.Char

Apart from stringobject, the aliases are all to value types. decimal is a value type, but not a primitive type in the CLR. The only primitive type which doesn't have an alias is System.IntPtr.

In the spec, the value type aliases are known as "simple types". Literals can be used for constant values of every simple type; no other value types have literal forms available. (Compare this with VB, which allows DateTimeliterals, and has an alias for it too.)

There is one circumstance in which you have to use the aliases: when explicitly specifying an enum's underlying type. For instance:

public enum Foo : UInt32 {} // Invalidpublic enum Bar : uint   {} // Valid

Finally, when it comes to which to use: personally I use the aliases everywhere for the implementation, but the CLR type for any APIs. It really doesn't matter too much which you use in terms of implementation - consistency among your team is nice, but no-one else is going to care. On the other hand, it's genuinely important that if you refer to a type in an API, you do so in a language neutral way. A method called "ReadInt32" is unambiguous, whereas a method called "ReadInt" requires interpretation. The caller could be using a language which defines an "int" alias for Int16, for example. The .NET framework designers have followed this pattern, good examples being in the BitConverter, BinaryReader and Convert classes.


2.datatype  alias

//C#:
using MyType = System.Int32; //define alias MyType for System.Int32
//Now we can use the alias MyType anywhere in our code instead of actual System.In32 like below
MyType myNumber=12;
Console.WriteLine(myNumber.ToString()); 
//If we want to change to System.Int64, We will simply change the alias, that’s it.
using MyType = System.Int64; 

string = alias(String)相关推荐

  1. C# String和string的区别

    C#中同时存在String与string MSDN中对string的说明: string is an alias for String in the .NET Framework.string是Str ...

  2. static string java_java:String类、static关键字、Arrays类、 Math类

    public voidStrMethodTest(){/** public int length () :返回此字符串的长度. * public String concat (String str) ...

  3. 转换ArrayList String 到String []数组[重复]

    本文翻译自:Convert ArrayList to String[] array [duplicate] This question already has an answer here: 这个问题 ...

  4. C#中的String和string有什么区别?还有ref关键字怎么用?

    String 和 string 没有区别 string 是 String 的别名 ref 关键字一般只用于函数参数中,这个参数是 struct 类型,而不是 class 类型 因为 class 类型在 ...

  5. shell中$后加引号有什么用($string和$'string')

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 有些时候在某些服务管理脚本中看到$"$string& ...

  6. 【错误记录】Kotlin 编译报错 ( Type mismatch: inferred type is String? but String was expected )

    文章目录 一.报错信息 二.解决方案 一.报错信息 Google Play 上架要求 Android 的编译版本 和 目标版本都要高于 30 才可以上传 ; 将 Android 的编译版本 和 目标版 ...

  7. C#String与string大小写的区别

    1.string是c#中的类,String是.net Framework的类(在c# IDE中不会显示蓝色)   2.C# string映射为.net Framework的String   3.如果用 ...

  8. Java提升篇:理解String 及 String.intern() 在实际中的应用

    String的深入解析 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些 ...

  9. python timeit class Timer()类 timeit(string, string) repeat(string, string) default_timer() 耗时检测 执行速度

    #! /usr/bin/env python3"""Tool for measuring execution time of small code snippets. 用 ...

最新文章

  1. 如何全面认识联邦学习
  2. Gartner:2019年七大AI科技趋势,百万行业将颠覆!
  3. 以后的note的方法
  4. WCF Chat获奖人的奖品展示
  5. mysql主从复制深入研究_mysql主从复制原理,深入探讨
  6. 【渝粤教育】电大中专新媒体营销实务 (10)作业 题库
  7. C/C++函数调用的几种方式
  8. java多线程 文件夹_Java多线程遍历文件夹,广度遍历加多线程加深度遍历结合
  9. [ SHELL编程 ] 远程服务器传输文件
  10. java连接redis集群
  11. java64字节指令包,JVM 字节码指令解析
  12. mysql zf_ZF 连接 Mysql
  13. TCP客户端和服务端
  14. vs2012 安装 InstallShield
  15. 进击的自走棋——《金铲铲之战》游戏体验报告
  16. 金陵科技学院计算机组成考试,2017-2017年度金陵科技学院材料期末考试整理.doc...
  17. 斯坦福大学公开课机器学习:Neural Networks,representation: non-linear hypotheses(为什么需要做非线性分类器)...
  18. 2022物联网工程保研经历分享(中科院计算所、中科院软件所、中科大、南大、华中科技大学、北航、哈工大、中山大学等)
  19. 期望DP——珂学送分
  20. 涉密计算机应按照存储 处理信息的密级管理,涉密计算机的密级应按照存储和处理信息的最高密级确定 - 作业在线问答...

热门文章

  1. r语言8c多字节字符串有错,R语言答疑:txt文件无法被R正确读入
  2. 【Zotero高效知识管理】(4)Zotero的文献管理、阅读及笔记知识管理
  3. 08 | 数据采集:如何自动化采集数据?
  4. Java 根据多边形坐标点 计算多边形面积
  5. 从模拟信号到数字信号
  6. Microsoft Edge 中的ie浏览器图标、右击新标签页打开功能的关闭方法
  7. 成为智者的四个敌人——唐望
  8. 2021年烟花爆竹生产单位安全生产管理人员免费试题及烟花爆竹生产单位安全生产管理人员考试总结
  9. 【计算方法】数值微积分
  10. win10安装linux子系统详细教程(非虚拟机方式)