# Lengthとcount 違い

**URL:** <https://forum.uipath.com/t/length-count/722227>\
**Category:** Studio\
**Tags:** question, studio, activities\
**Created:** [February 25, 2024, 1:08pm UTC](https://forum.uipath.com/t/length-count/722227 "2024-02-25T13:08:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![natsumikan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/natsumikan/32/177170_2.png) [@natsumikan](https://forum.uipath.com/u/natsumikan)\
**Post date:** [February 25, 2024, 1:08pm UTC](https://forum.uipath.com/t/length-count/722227/1 "2024-02-25T13:08:24Z")

</div>

フォルダ内ののファイルを全て取得（getfilesメソッドで取得）し、フォルダ内のファイル存在有無判定をしようと考えています。

Length＝0とcount＝0どちらを使おうか悩んでいるのですが、この二つの違いってなんでしょうか

---

<div class="post-metadata">

**Author:** ![Parvathy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/parvathy/32/484539_2.png) [@Parvathy](https://forum.uipath.com/u/Parvathy)\
**Post date:** [February 25, 2024, 1:10pm UTC](https://forum.uipath.com/t/length-count/722227/2 "2024-02-25T13:10:50Z")

</div>

Hi @natsumikan

**Length** : This property is typically used with arrays. It returns the total number of elements in the array.

Example:

```auto
array.Length

```

**Count** : This property is used with collections such as lists, dictionaries, or enumerable types. It returns the number of elements in the collection.

Example:

```auto
list.Count

```

In your case, if you’re using `GetFiles` method in UiPath, it returns an array of strings representing the files in the specified directory. Therefore, you should use `.Length` to get the number of files in the folder.

Example in UiPath:

```auto
arrFiles = Directory.GetFiles("C:\YourFolderPath")
If arrFiles.Length > 0 Then
    // Files exist
Else
    // No files exist
End If

```

Hope it helps!!

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [February 25, 2024, 2:12pm UTC](https://forum.uipath.com/t/length-count/722227/3 "2024-02-25T14:12:15Z")

</div>

こんにちは

結論から言うと、今回の例のように対象が配列の場合はLengthの方が良いと思います。  
それぞれ、Array.Lengthプロパティと、Enumerable.Countメソッドになりますが、Lengthの方が値の取得コストが小さい＝軽いと思います。  
なお対象が`List<T>`の場合はCountプロパティがあるので、こちらを使います。

 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/4/d/74d1a6da9261aa4a212ae0444c0c5c8ff943d6b1.png)

> **[Array.Length プロパティ (System)](https://learn.microsoft.com/ja-jp/dotnet/api/system.array.length?view=net-8.0)**
>
> Array のすべての次元内の要素の総数を取得します。

> **[Enumerable.Count メソッド (System.Linq)](https://learn.microsoft.com/ja-jp/dotnet/api/system.linq.enumerable.count?view=net-8.0)**
>
> シーケンス内の要素数を返します。

ちなみに、配列の要素数をチェックするのであれば、条件式として

```
arrFile.Any()

```

のように記述することも可能です。（上記は配列に１つ以上要素があれば、Trueが返ります）
