C# 配列、String型

String型 と配列って意外と関わりが深いのね

 

 

//C#のstring型は, System.String型

 

面白かったのは C#で使ってるデータ型は

 

「組み込みデータ型」

 

ようするに、

.NET.Framwork 名前空間で定義されている

System.String

System.Int32

 

とか、じゃあなんで[int]でつかえるかというと、

エイリアス機能(別名機能)>で

本来の名前    エイリアス

System.String → string

System.Int32  → int

 

となっていて、同じ名前として扱えるから。

 

知らんかった。てっきりデータ型くらいは、OSにデータ型用意してて使ってんのかと思ってたw

 

ゴールからはじめるC# 参照;P65

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


    class Program
    {
        static void Main(string[] args)
        {

            string str1 = "ABC", str2 = "あいうえええおおお";

            char c = str1[2];

            Console.WriteLine(c);

            
            //C#のstring型は, System.String型
            //文字数を取得 .これはプロパティ

            int length1 = str1.Length;
            int length2 = str2.Length;



            Console.WriteLine(length1);
            Console.WriteLine(length2);
        }
    }