ArrayList.IsSynchronized プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ArrayList.IsSynchronized プロパティの意味・解説 

ArrayList.IsSynchronized プロパティ

ArrayList へのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable ReadOnly
 Property IsSynchronized As Boolean
Dim instance As ArrayList
Dim value As Boolean

value = instance.IsSynchronized
public virtual bool IsSynchronized { get;
 }
public:
virtual property bool IsSynchronized {
    bool get ();
}
/** @property */
public boolean get_IsSynchronized ()
public function get IsSynchronized
 () : boolean

プロパティ
ArrayList へのアクセス同期されている (スレッド セーフである) 場合trueそれ以外場合false既定値false です。

解説解説
使用例使用例

列挙処理中に SyncRoot を使用してコレクションロックする方法次のコード例示します

ArrayList myCollection = new ArrayList();
  lock(myCollection.SyncRoot) {
  foreach (Object item in myCollection) {
  // Insert your code here.
  }
 }
Dim myCollection As New
 ArrayList()
 Dim item As Object
 SyncLock myCollection.SyncRoot
  For Each item In myCollection
  ' Insert your code here.
  Next item
 End SyncLock

このプロパティ値を取得することは、O(1) 操作なります

ArrayList同期する方法と、ArrayList同期されているかどうか確認し同期済みArrayList使用する方法次のコード例示します

Imports System
Imports System.Collections

Public Class SamplesArrayList
    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new ArrayList.
        Dim myAL As New
 ArrayList()
        myAL.Add("The")
        myAL.Add("quick")
        myAL.Add("brown")
        myAL.Add("fox")
        
        ' Creates a synchronized wrapper around the ArrayList.
        Dim mySyncdAL As ArrayList = ArrayList.Synchronized(myAL)
        
        ' Displays the sychronization status of both ArrayLists.
        Dim str As String
        If myAL.IsSynchronized Then
            str = "synchronized"
        Else
            str = "not synchronized"
        End If
        Console.WriteLine("myAL is {0}.", str)
        If mySyncdAL.IsSynchronized Then
            str = "synchronized"
        Else
            str = "not synchronized"
        End If
        Console.WriteLine("mySyncdAL is {0}.", str)
    End Sub
End Class

' This code produces the following output.
' 
' myAL is not synchronized.
' mySyncdAL is synchronized. 
using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()
  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add( "The" );
      myAL.Add( "quick" );
      myAL.Add( "brown" );
      myAL.Add( "fox" );

      // Creates a synchronized wrapper around the ArrayList.
      ArrayList mySyncdAL = ArrayList.Synchronized( myAL );

      // Displays the sychronization status of both ArrayLists.
      Console.WriteLine( "myAL is {0}.", myAL.IsSynchronized ? "synchronized"
 : "not synchronized" );
      Console.WriteLine( "mySyncdAL is {0}.", mySyncdAL.IsSynchronized
 ? "synchronized" : "not synchronized" );
   }
}
/* 
This code produces the following output.

myAL is not synchronized.
mySyncdAL is synchronized.
*/ 
using namespace System;
using namespace System::Collections;
int main()
{
   
   // Creates and initializes a new ArrayList instance.
   ArrayList^ myAL = gcnew ArrayList;
   myAL->Add( "The" );
   myAL->Add( "quick" );
   myAL->Add( "brown" );
   myAL->Add( "fox" );
   
   // Creates a synchronized wrapper around the ArrayList.
   ArrayList^ mySyncdAL = ArrayList::Synchronized( myAL );
   
   // Displays the sychronization status of both ArrayLists.
   String^ szRes = myAL->IsSynchronized ?  (String^)"synchronized" :
  "not synchronized";
   Console::WriteLine(  "myAL is {0}.", szRes );
   String^ szSyncRes = mySyncdAL->IsSynchronized ?  (String^)"synchronized"
 :  "not synchronized";
   Console::WriteLine(  "mySyncdAL is {0}.", szSyncRes );
}

/* 
 This code produces the following output.
 
 myAL is not synchronized.
 mySyncdAL is synchronized.
 */
import System.*;
import System.Collections.*;

public class SamplesArrayList
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("The");
        myAL.Add("quick");
        myAL.Add("brown");
        myAL.Add("fox");

        // Creates a synchronized wrapper around the ArrayList.
        ArrayList mySyncdAL = ArrayList.Synchronized(myAL);

        // Displays the sychronization status of both ArrayLists.
        Console.WriteLine("myAL is {0}.", myAL.get_IsSynchronized()
            ? "synchronized" : "not synchronized");
        Console.WriteLine("mySyncdAL is {0}.", mySyncdAL.get_IsSynchronized()
            ? "synchronized" : "not synchronized");
    } //main
} //SamplesArrayList
/* 
 This code produces the following output.
 
 myAL is not synchronized.
 mySyncdAL is synchronized.
 */
import System;
import System.Collections;

// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );

// Creates a synchronized wrapper around the ArrayList.
var mySyncdAL : ArrayList  = ArrayList.Synchronized( myAL );

// Displays the sychronization status of both ArrayLists.
Console.WriteLine( "myAL is {0}.", myAL.IsSynchronized ? "synchronized"
 : "not synchronized" );
Console.WriteLine( "mySyncdAL is {0}.", mySyncdAL.IsSynchronized ? "synchronized"
 : "not synchronized" );
 
 /* 
 This code produces the following output.
 
 myAL is not synchronized.
 mySyncdAL is synchronized.
 */ 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ArrayList.IsSynchronized プロパティ」の関連用語

ArrayList.IsSynchronized プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ArrayList.IsSynchronized プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS