当前位置:网站首页>U++ programming array learning notes

U++ programming array learning notes

2022-06-22 14:53:00 It's a bald rabbit

Tarray

establish :

TArray<int32> IntArray;

Assign initial value to :

IntArray.Init(10, 5);
// IntArray == [10,10,10,10,10]

Add and Emplace Function to create a new element at the end of the array :

TArray<FString> StrArr;
StrArr.Add    (TEXT("Hello"));
StrArr.Emplace(TEXT("World"));
// StrArr == ["Hello","World"]

Append Add multiple elements from one at a time TArray, Or add a point to general C The pointer to the array and the size of the array :

FString Arr[] = { TEXT("of"), TEXT("Tomorrow") };
StrArr.Append(Arr, ARRAY_COUNT(Arr));
// StrArr == ["Hello","World","of","Tomorrow"]

 AddUnique Add a new element to the container only if the equivalent element does not already exist . Use element types to check for equivalence operator==

StrArr.AddUnique(TEXT("!"));
// StrArr == ["Hello","World","of","Tomorrow","!"]

StrArr.AddUnique(TEXT("!"));
// StrArr is unchanged as "!" is already an element

 Insert Insert at a location :

StrArr.Insert(TEXT("Brave"), 1);
// StrArr == ["Hello","Brave","World","of","Tomorrow","!"]

  The SetNum Function can directly set the number of array elements , If the new element is larger than the current element , Then use the default constructor of the element type to create a new element :

StrArr.SetNum(8);
// StrArr == ["Hello","Brave","World","of","Tomorrow","!","",""]

SetNum If the new number is less than the current number , The element will also be deleted . More details about element deletion will be provided later : 

StrArr.SetNum(6);
// StrArr == ["Hello","Brave","World","of","Tomorrow","!"]
原网站

版权声明
本文为[It's a bald rabbit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221321591170.html