C#C
C#3y ago
5 replies
JJ

❔ char and character size difference

Im wandering why beteween char size having 2 byte and character size having 1byte is differ.
character isn't it 2byte since char data type?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CS_Tutorial
{
  internal class Program
  {
    static void Main(string[] args)
    {
      string abc = "abcdefg";
      int size = Marshal.SizeOf(abc[0]);
      Console.WriteLine(size);
      Console.WriteLine(sizeof(char));
      
    }
  }
}
Was this page helpful?