SortedList.SetByIndex メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SortedList.SetByIndex メソッドの意味・解説 

SortedList.SetByIndex メソッド

SortedList特定のインデックスにある値を置換します。

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

Public Overridable Sub SetByIndex
 ( _
    index As Integer, _
    value As Object _
)
Dim instance As SortedList
Dim index As Integer
Dim value As Object

instance.SetByIndex(index, value)
public void SetByIndex (
    int index, 
    Object value
)

パラメータ

index

value保存する位置の、0 から始まるインデックス番号

value

SortedList に保存する Object。値は null 参照 (Visual Basic では Nothing) に設定できます

例外例外
例外種類条件

ArgumentOutOfRangeException

index が、SortedList有効なインデックス範囲外です。

解説解説
使用例使用例

SortedList に既に存在する要素の値を置換する方法の例を次に示します

Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesSortedList    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new SortedList.
        Dim mySL As New
 SortedList()
        mySL.Add(2, "two")
        mySL.Add(3, "three")
        mySL.Add(1, "one")
        mySL.Add(0, "zero")
        mySL.Add(4, "four")
        
        ' Displays the values of the SortedList.
        Console.WriteLine("The SortedList contains the following"
 & _
           "values:")
        PrintIndexAndKeysAndValues(mySL)
        
        ' Replaces the values at index 3 and index 4.
        mySL.SetByIndex(3, "III")
        mySL.SetByIndex(4, "IV")
        
        ' Displays the updated values of the SortedList.
        Console.WriteLine("After replacing the value at index
 3 and index 4,")
        PrintIndexAndKeysAndValues(mySL)
    End Sub 'Main
    
    
    
    Public Shared Sub PrintIndexAndKeysAndValues(myList
 As SortedList)
        Console.WriteLine(ControlChars.Tab & "-INDEX-"
 & ControlChars.Tab & _
           "-KEY-" & ControlChars.Tab & "-VALUE-")
        Dim i As Integer
        For i = 0 To myList.Count - 1
            Console.WriteLine(ControlChars.Tab & "[{0}]:"
 & ControlChars.Tab & _
               "{1}" & ControlChars.Tab &
 "{2}", i, myList.GetKey(i), _
               myList.GetByIndex(i))
        Next i
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The SortedList contains the following values:
'     -INDEX-    -KEY-    -VALUE-
'     [0]:    0    zero
'     [1]:    1    one
'     [2]:    2    two
'     [3]:    3    three
'     [4]:    4    four
' 
' After replacing the value at index 3 and index 4,
'     -INDEX-    -KEY-    -VALUE-
'     [0]:    0    zero
'     [1]:    1    one
'     [2]:    2    two
'     [3]:    3    III
'     [4]:    4    IV
using System;
using System.Collections;
public class SamplesSortedList  {

   public static void Main()
  {

      // Creates and initializes a new SortedList.
      SortedList mySL = new SortedList();
      mySL.Add( 2, "two" );
      mySL.Add( 3, "three" );
      mySL.Add( 1, "one" );
      mySL.Add( 0, "zero" );
      mySL.Add( 4, "four" );

      // Displays the values of the SortedList.
      Console.WriteLine( "The SortedList contains the following values:"
 );
      PrintIndexAndKeysAndValues( mySL );

      // Replaces the values at index 3 and index 4.
      mySL.SetByIndex( 3, "III" );
      mySL.SetByIndex( 4, "IV" );

      // Displays the updated values of the SortedList.
      Console.WriteLine( "After replacing the value at index 3 and index 4,"
 );
      PrintIndexAndKeysAndValues( mySL );
   }


   public static void PrintIndexAndKeysAndValues(
 SortedList myList )  {
      Console.WriteLine( "\t-INDEX-\t-KEY-\t-VALUE-" );
      for ( int i = 0; i < myList.Count;
 i++ )  {
         Console.WriteLine( "\t[{0}]:\t{1}\t{2}", i, myList.GetKey(i),
 myList.GetByIndex(i) );
      }
      Console.WriteLine();
   }
}
/* 
This code produces the following output.

The SortedList contains the following values:
    -INDEX-    -KEY-    -VALUE-
    [0]:    0    zero
    [1]:    1    one
    [2]:    2    two
    [3]:    3    three
    [4]:    4    four

After replacing the value at index 3 and index 4,
    -INDEX-    -KEY-    -VALUE-
    [0]:    0    zero
    [1]:    1    one
    [2]:    2    two
    [3]:    3    III
    [4]:    4    IV
*/ 
#using <system.dll>

using namespace System;
using namespace System::Collections;
void PrintIndexAndKeysAndValues( SortedList^ myList )
{
   Console::WriteLine( "\t-INDEX-\t-KEY-\t-VALUE-" );
   for ( int i = 0; i < myList->Count;
 i++ )
   {
      Console::WriteLine( "\t[{0}]:\t{1}\t{2}", i, myList->GetKey( i
 ), myList->GetByIndex( i ) );

   }
   Console::WriteLine();
}

int main()
{
   
   // Creates and initializes a new SortedList.
   SortedList^ mySL = gcnew SortedList;
   mySL->Add( 2, "two" );
   mySL->Add( 3, "three" );
   mySL->Add( 1, "one" );
   mySL->Add( 0, "zero" );
   mySL->Add( 4, "four" );
   
   // Displays the values of the SortedList.
   Console::WriteLine( "The SortedList contains the following values:"
 );
   PrintIndexAndKeysAndValues( mySL );
   
   // Replaces the values at index 3 and index 4.
   mySL->SetByIndex( 3, "III" );
   mySL->SetByIndex( 4, "IV" );
   
   // Displays the updated values of the SortedList.
   Console::WriteLine( "After replacing the value at index 3 and index 4,"
 );
   PrintIndexAndKeysAndValues( mySL );
}

/*
This code produces the following output.

The SortedList contains the following values:
        -INDEX- -KEY-   -VALUE-
        [0]:    0       zero
        [1]:    1       one
        [2]:    2       two
        [3]:    3       three
        [4]:    4       four

After replacing the value at index 3 and index 4,
        -INDEX- -KEY-   -VALUE-
        [0]:    0       zero
        [1]:    1       one
        [2]:    2       two
        [3]:    3       III
        [4]:    4       IV
*/
import System.*;
import System.Collections.*;

public class SamplesSortedList
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new SortedList.
        SortedList mySL = new SortedList();

        mySL.Add((Int32)2, "two");
        mySL.Add((Int32)3, "three");
        mySL.Add((Int32)1, "one");
        mySL.Add((Int32)0, "zero");
        mySL.Add((Int32)4, "four");

        // Displays the values of the SortedList.
        Console.WriteLine("The SortedList contains the following values:");
        PrintIndexAndKeysAndValues(mySL);

        // Replaces the values at index 3 and index 4.
        mySL.SetByIndex(3, "III");
        mySL.SetByIndex(4, "IV");

        // Displays the updated values of the SortedList.
        Console.WriteLine("After replacing the value at index 3 and index 4
,");
        PrintIndexAndKeysAndValues(mySL);
    } //main

    public static void PrintIndexAndKeysAndValues(SortedList
 myList)
    {
        Console.WriteLine("\t-INDEX-\t-KEY-\t-VALUE-");
        for (int i = 0; i < myList.get_Count();
 i++) {
            Console.WriteLine("\t[{0}]:\t{1}\t{2}", 
                System.Convert.ToString(i), 
                System.Convert.ToString(myList.GetKey(i)), 
                System.Convert.ToString(myList.GetByIndex(i)));
        }
        Console.WriteLine();
    } //PrintIndexAndKeysAndValues

} //SamplesSortedList

/* 
 This code produces the following output.
 
 The SortedList contains the following values:
        -INDEX- -KEY-   -VALUE-
        [0]:    0       zero
        [1]:    1       one
        [2]:    2       two
        [3]:    3       three
        [4]:    4       four

 After replacing the value at index 3 and index 4,
        -INDEX- -KEY-   -VALUE-
        [0]:    0       zero
        [1]:    1       one
        [2]:    2       two
        [3]:    3       III
        [4]:    4       IV
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SortedList クラス
SortedList メンバ
System.Collections 名前空間
IndexOfKey
IndexOfValue


このページでは「.NET Framework クラス ライブラリ リファレンス」からSortedList.SetByIndex メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSortedList.SetByIndex メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSortedList.SetByIndex メソッド を検索

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

辞書ショートカット

すべての辞書の索引

SortedList.SetByIndex メソッドのお隣キーワード
検索ランキング

   

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



SortedList.SetByIndex メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS