Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Boolean.Parse() วิธีการใน C #


Boolean.Parse() วิธีการใน C # ใช้เพื่อแปลงการแสดงสตริงที่ระบุของค่าตรรกะให้เทียบเท่าบูลีน

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ -

public static bool Parse (string val);

ด้านบน ค่าพารามิเตอร์คือสตริงที่มีค่าที่จะแปลง

ตัวอย่าง

ให้เราดูตัวอย่างการใช้เมธอด Boolean.Parse() -

using System;
public class Demo {
   public static void Main(){
      bool b;
      b = bool.Parse("FALSE");
      Console.WriteLine("After parsing = "+b);
   }
}

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

After parsing = False

ตัวอย่าง

เรามาดูตัวอย่างกัน −

using System;
public class Demo {
   public static void Main(){
      bool b;
      b = bool.Parse(bool.TrueString);
      Console.WriteLine("After parsing = "+b);
   }
}

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

After parsing = True