using System;
using System.Collections.Generic;
using System.Text;
namespace LeetCode2019
{
public static class Basic
{
public static void BasicDataStructure()
{
//Primitive data types
bool myBool = true;
byte myByte = 101; // 0 - 255
sbyte mySbyte = 1; // -128 to 127
char myChar = 'a'; //U+0000 to U+FFFF
decimal myDecimal = 300.5m; //±1.0 x 10(-28) to ±7.9228 x 10(+28)
double myDouble = 33.4d;
float myFloat = 33.44f;
int myInt = -5;
uint myUInt = 5;
long myLong = 1000000000000;
ulong myULong = 1000000;
object myObject = new object();
short myShort = 255; //-32,768 to 32,767 Signed 16-bit integer
ushort myUShort = 32776; //0 to 65,535 Unsigned 16-bit integer
string myString = "abc";
//Array :https://www.geeksforgeeks.org/c-sharp-arrays/
//Syntax:
//<Data Type>[] <Name_Array> = new <datatype> [size];
int[] intArray1 = new int[5]; //default value is 0
int[] intArray2 = new int[5] { 1, 2, 3, 4, 5 };
int[] intArray3 = { 1, 2, 3, 4, 5 };
for (int i = 0; i < intArray1.Length; i++)
{
Console.WriteLine(intArray1[i]);
}
//Multidimensional Arrays, (Rectangular Array)
int[,] intArray2D = new int[4, 2]; //two dimensional array
int[,,] intArray3D = new int[4, 2, 3]; // three dimensional array
C#基本数据类型 和数据结构
最新推荐文章于 2024-02-21 19:10:44 发布
本文详细介绍了C#编程语言中的基本数据类型,包括整型、浮点型、布尔型、字符型等,并深入探讨了C#中的数据结构,如数组、列表和字典的使用方法及其在实际编程中的应用。通过阅读,读者将能够掌握C#中数据类型的选用和数据结构的实现技巧。
摘要由CSDN通过智能技术生成