Created
May 29, 2020 22:16
-
-
Save luiseduardohd/8267f71018b640ad08069a2f8e42ff7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine("Hello World"); | |
string ipString = "192.168. 1.1"; | |
Console.WriteLine("isValidIPV4 "+ipString+":"+isValidIPV4(ipString)); | |
} | |
static bool isValidIPV4(string address) | |
{ | |
if ( address == null ) | |
return false; | |
if ( address == "" ) | |
return false; | |
var numbers = address.Split('.'); | |
if (numbers.Length != 4) | |
return false; | |
foreach (var stringNumber in numbers) | |
{ | |
int number; | |
bool success = Int32.TryParse(stringNumber, out number); | |
if (success == false) | |
return false; | |
if (!(0 <= number && number <= 255)) | |
return false; | |
} | |
return true; | |
} | |
} |
Write logic using C# to validate an IPV4 address format. (a method which takes string as parameter and returns boolean as response)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code made for a call interview