Digging C # series of things that we don't commonly use (2) -- isxxx Series Method

Source: Internet
Author: User
Original article: digging C # series of things we don't commonly use (2) -- isxxx Series Method

 

I don't know whether someone has done outsourcing to Japan. If I have done it, I should be very familiar with VB.net. When I first graduated, I had outsourcing for four months.

Even the aunts who bought jewelry under the Building said that these children had only seen them go to work and never saw them go off work, but it was a little better, there's a QA girl.

Point to teach us the melon language, and now we are still hooked up...

Now let's look at the requirements.

 

I. How to determine whether "a" is of the numerical type.

①: In C #, we may use tryparse to determine whether the current "a" is an integer.

 1         static void Main(string[] args) 2         { 3             var a = "a"; 4  5             int r; 6  7             Console.WriteLine(int.TryParse(a, out r)); 8  9             Console.Read();10         }

I think everyone is familiar with this tryparse, but the most annoying thing is that I just want to know if "A" is an integer and define an R variable.

 

② Use regular expressions

The omnipotent regular expression cannot solve the problem without it. But for it, I still need to write "expressions", which is a little troublesome. I don't like it. I need a simpler method.

1             var a = "a";2 3             Console.WriteLine(Regex.IsMatch(a, "^\\d$"));4 5             Console.Read();

 

③: If you know VB.net, you will certainly know that there is an isnumeric method in VB.

1     Sub Main()2 3         Dim a As String = "a"4 5         Console.WriteLine(IsNumeric(a))6 7         Console.Read()8 9     End Sub

 

When you see this method, is it nice? Let's continue to figure out the namespace. If we know the namespace, can we use C # to solve the problem?

 

Okay, now we have wiped out the TA, but in the Microsoft. VisualBasic space, we also saw Seven seemingly useful isxxx, which is great ~~~

Next we will add a reference.

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using Microsoft.VisualBasic; 7 using System.Diagnostics; 8  9 namespace ConsoleApplication110 {11     class Program12     {13         static void Main(string[] args)14         {15             var a = "a";16 17             Console.WriteLine(Information.IsNumeric(a));18 19             Console.Read();20         }21     }22 }

 

These isxxx methods are very well-known and I don't need to explain them again. If you are interested, you can try them by yourself. These methods are very useful,

You can't do it ~ For example, in the isdate method, it is troublesome to judge whether a string is time in C #, either tryparse, regular, and total

VS is a big platform. When C # is not easy to implement, you can think about whether you can reference the methods in other languages ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.