Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode a single id. #57

Merged
merged 16 commits into from
Mar 30, 2022
Merged

Decode a single id. #57

merged 16 commits into from
Mar 30, 2022

Conversation

Cereal-Killa
Copy link
Contributor

@Cereal-Killa Cereal-Killa commented Mar 28, 2022

Based on issue #53.

Usage:

var hashid = new Hashids("123456789");
int id = hashid.DecodeSingle("NkK9");

or

var hashid = new Hashids("123456789");

try
{
    int id = hashid.DecodeSingle("NkK9");
}
catch (MultipleResultsException)
{
    //Handle exception when the hash returns more than one id.
}

or

int id;

if (hashid.TryDecodeSingle("NkK9,NkK9", out id))
{
   Console.WriteLine(id.ToString());
}
else
{
   Console.WriteLine("Invalid Id");
}

The logic same applies to long values: DecodeSingleLong.

image

image

image

src/Hashids.net/Hashids.cs Outdated Show resolved Hide resolved
src/Hashids.net/Hashids.cs Outdated Show resolved Hide resolved
src/Hashids.net/Hashids.cs Outdated Show resolved Hide resolved
src/Hashids.net/Hashids.cs Outdated Show resolved Hide resolved
@manigandham
Copy link
Collaborator

Thanks @Cereal-Killa @warappa @KeterSCP

@manigandham manigandham merged commit 26861a7 into ullmark:master Mar 30, 2022
@Cereal-Killa Cereal-Killa deleted the single-return branch April 1, 2022 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants