6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#で.NET Frameworkを使用するときのstring型とString型の違い

Last updated at Posted at 2016-06-26

概要

文字列を扱うときに、string型とString型どちらも扱えてしまえてどちらを使用すればいいんでしょう…となって調べました。

  • 結論どちらを使用しても一緒です。
  • int型はInt32でなくてintって宣言してるのでstringって宣言した方が統一感ありそうです。

本題

共通型システム

  • .NET Frameworkには共通ランタイム(Common Language Runtime、CLR)という実行環境があります。
  • CLRはC#をはじめとする.NET Framework対応の言語で書かれたプログラム1を動かすための環境です。

  • CLRの機能の1つに共通型システム(CTS)があり、型と演算をサポートしています。

CTSとC♯

  • C#が用意している基本データ型はCTSが提供するデータ型のエイリアスになっています。
  • 下表の様な対応関係になっています。
C#の型 CTSの型 型の種類
object System.Object クラス
bool System.Boolean 構造体
char System.Char 構造体
ushort System.UInt16 構造体
int System.Int32 構造体
long System.Int64 構造体
double System.Double 構造体
string System.String クラス
  • 同じ意味
int num = 123;
System.Int32 num = 123;

 参考


  1. C#の他にはF#、Visual Basic等。 

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?