C#
 Computer >> コンピューター >  >> プログラミング >> C#

パラメータをスレッドに渡すC#プログラム


スレッドを操作するには、コードに次の名前空間を追加します-

using System.Threading;

まず、C#で新しいスレッドを作成する必要があります-

Thread thread = new Thread(threadDemo);

上記のthreadDemoはスレッド関数です。

次に、パラメータをスレッドに渡します-

thread.Start(str);

上記のパラメータセットは-

です
String str = "Hello World!";
C#のスレッドにパラメーターを渡すための完全なコードを見てみましょう。

using System;
using System.Threading;
namespace Sample {
   class Demo {
      static void Main(string[] args) {
         String str = "Hello World!";
         // new thread
         Thread thread = new Thread(threadDemo);
         // passing parameter
         thread.Start(str);
      }
      static void threadDemo(object str) {
         Console.WriteLine("Value passed to the thread: "+str);
      }
   }
}
出力
Value passed to the thread: Hello World!

  1. 大文字と小文字を変換するC#プログラム

    文字列が-だとしましょう str = "AMIT"; 上記の大文字の文字列を小文字に変換するには、ToLower()メソッド-を使用します。 Console.WriteLine("Converted to LowerCase : {0}", str.ToLower()); 例 以下は、大文字と小文字を変換するためのC#のコードです。 using System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplic

  2. 現在のスレッドのステータスをチェックするC#プログラム

    C#で現在のスレッドのステータスを確認するには、 IsAliveを使用します プロパティ。 まず、 currentThreadを使用します スレッドに関する情報を表示するプロパティ- Thread thread = Thread.CurrentThread; 次に、 thread.IsAliveを使用します スレッドのステータスをチェックするプロパティ- thread.IsAlive 例 C#で現在のスレッドのステータスを確認するための完全なコードを見てみましょう。 using System; using System.Threading; namespace Demo {