How to try parse bool value from a string in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "true";

            bool b;
            if (bool.TryParse(s, out b))
                Console.WriteLine(b);

            s = "c#";

            if (bool.TryParse(s, out b))
                Console.WriteLine(b);
        }
    }
}

/*
run:
   
True

*/

 



answered Jan 17, 2017 by avibootz

Related questions

1 answer 178 views
178 views asked Jan 17, 2017 by avibootz
1 answer 211 views
1 answer 176 views
1 answer 189 views
1 answer 202 views
1 answer 159 views
...