Skip to content

Instantly share code, notes, and snippets.

@luiseduardohd
Created May 29, 2020 22:16
Show Gist options
  • Save luiseduardohd/8267f71018b640ad08069a2f8e42ff7e to your computer and use it in GitHub Desktop.
Save luiseduardohd/8267f71018b640ad08069a2f8e42ff7e to your computer and use it in GitHub Desktop.
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;
}
}
@luiseduardohd
Copy link
Author

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