Settings Results in 4 milliseconds

Data structure in C-Sharp Software Development Not ...
Category: Algorithms

In this article, I will keep notes about different #data #structures and why I should use ...


Views: 0 Likes: 39
Determine if two strings are anagrams with C# .NET
Determine if two strings are anagrams with C# .NET

Two strings are anagrams if they are made up of the same set of characters. Examples “hello” and “loleh”“123123” and “312312”“qwerty” and “wretqy” The degree of “anagram-ness” can vary ignore case?ignore non-numeric characters?ignore whitespace? In this post we’ll only consider word-characters only and the comparison will be case-insensitive to make the problem more interesting. We’ll write a function that accepts two integers and returns a boolean true if the strings are anagrams, otherwise false. We’ll look at two solutions out of many that exist out there using a character mapusing string sort What is a character map? It is a map where the key is of type char and the value if of type integer. We collect the unique characters of a string and count how many times each character occurs in the string. E.g. CharCount‘f’2‘g’1‘i’2‘d’1‘o’1 We do that for both strings and compare the counts of each unique character. Let’s start with a skeleton using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Algorithms { public class Anagram { public bool AreAnagrams(string first, string second) { if (first == null || second == null) return false; return AreAnagramsWithCharMap(first, second); //return AreAnagramsWithSortedStrings(first, second); } private bool AreAnagramsWithCharMap(string first, string second) { return false; } private bool AreAnagramsWithSortedStrings(string first, string second) { return false; } private Dictionary<char, int> MakeCharacterMap(string input) { string cleaned = CleanInput(input); return cleaned.Distinct().ToDictionary(c => c, c => cleaned.Count(s => s == c)); } private string CleanInput(string input) { return Regex.Replace(input, @"[_]+|[^\w]+|[\d-]+", "").ToLower(); } } } We start by some null-checking and return false if either of the two inputs is null. The AreAnagramsWithCharMap function has been wired up but it’s not yet implemented. The function for the second solution AreAnagramsWithSortedStrings has also been prepared. We have two private functions as well CleanInputthis one takes a string and strips all underscores, white space and non-word characters from it and returns the lower-case version of itMakeCharacterMapfirst we clean the incoming input stringsecond we use a couple of LINQ operators to build the character mapDistinct() to gather the unique characters from the stringToDictionary() to build the map itself, the key will be the character itself and for the value we count the number of occurrences of that character in the string Let’s look at the implementation of AreAnagramsWithCharMap private bool AreAnagramsWithCharMap(string first, string second) { var charMapFirst = MakeCharacterMap(first); var charMapSecond = MakeCharacterMap(second); if (charMapFirst.Count != charMapSecond.Count) { return false; } return charMapFirst.All(kvp => charMapSecond.ContainsKey(kvp.Key) ? kvp.Value == charMapSecond[kvp.Key] false); } We first create the two character maps. If they differ in size then we can immediately return false. It means that one of the strings has at least one more character than the other so it’s pointless to continue. Otherwise we make use of the All LINQ operator which return true of all the elements of a collection fulfil a certain condition. The condition is based on two parameters whether the character map contains the character as the key in the first placewhether that character occurs with the same frequency as in the source map If both conditions are fulfilled for all characters in the character maps then we return true. Here’s a set of unit tests using System; using System.Collections.Generic; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Algorithms.Tests { [TestClass] public class AnagramTests { [TestMethod] public void AreAnagramsTests() { Anagram a = new Anagram(); Assert.IsTrue(a.AreAnagrams("hello", "___ hllOe!! 456 ???")); Assert.IsFalse(a.AreAnagrams("sdfs", null)); Assert.IsFalse(a.AreAnagrams(null, "sdfs")); Assert.IsFalse(a.AreAnagrams(null, null)); Assert.IsFalse(a.AreAnagrams("qwerty", "yewr")); Assert.IsFalse(a.AreAnagrams("qwerty", "qwertyuiop")); Assert.IsTrue(a.AreAnagrams("? par**lIame%%nt !", "partIAL men")); Assert.IsTrue(a.AreAnagrams("a gentleman", "elegant man")); } } } The will all pass. The second solution takes the two cleaned strings, puts them in order and compares them. This solution is slightly less performant than the first one due to the string ordering though. The map comparison doesn’t involve any ordering so it’s somewhat quicker. Here’s the implemented function private bool AreAnagramsWithSortedStrings(string first, string second) { string sortedOne = string.Concat(CleanInput(first).OrderBy(c => c)); string sortedTwo = string.Concat(CleanInput(second).OrderBy(c => c)); return sortedOne == sortedTwo; } We again clean the input string and then call the OrderBy LINQ operator. It returns an ordered collection of characters from the string, i.e. not an ordered string. Hence we need to embed this bit of code in string.Concat so that we build the string again from the characters. Finally we simply compare the two strings. Wire up this function from the main one and rerun the unit tests. They will still pass. public bool AreAnagrams(string first, string second) { if (first == null || second == null) return false; //return AreAnagramsWithCharMap(first, second); return AreAnagramsWithSortedStrings(first, second); }


Add a #FingerPrint reader to a C# WinForms app
Add a #FingerPrint reader to a C# WinForms app

Probably a good way to add extra security to a Windows Form app, just to make sure that there is a real human user infront of the screen, and it’s not some bot trying to interact with your software, is to add a Fingerprint / “Windows Hello” login. Of course, in the real world, generally the attacker would probably try to de-compile your software and try to attack whatever underlying API you are using. However, this is a very visible security feature, and if you’re looking for a super-quick security addition, then, this may be an interesting addition. Windows Hello is a biometric authentication feature that allows users to log into their Windows device using a fingerprint scanner, facial recognition, or other biometric methods, rather than a password. Some potential use cases for including Windows Hello in a WinForms app include Secure login By using a fingerprint scanner or other biometric method, you can add an additional layer of security to your app and make it more difficult for unauthorized users to access the app. Convenience Allowing users to log in with a fingerprint or other biometric method can make the login process more convenient for them, as they don’t have to remember a password or enter it manually. Compliance Depending on the nature of the app and the industries it serves, biometric authentication may be required by compliance regulations or industry standards. User experience For some users, biometric authentication is a preferred way to interact with their devices, and they feel more secure with that kind of security. Protecting sensitive data If your app handles sensitive information, such as financial data or personal information, biometric authentication can help ensure that only authorized users have access to this information. Here is a link to a public GitHub Repo that shows a simple example of this in action https//github.com/infiniteloopltd/FingerPrintReader The Key code being; var supported = await KeyCredentialManager.IsSupportedAsync(); if (!supported) return; var result = await KeyCredentialManager.RequestCreateAsync("login", KeyCredentialCreationOption.ReplaceExisting); if (result.Status == KeyCredentialStatus.Success) { MessageBox.Show("Logged in."); } else { MessageBox.Show("Login failed."); }


C-Sharp 11 Tips and Tricks
Category: Research

Linq- Did you know you could compair two sequences by using sequence operations li ...


Views: 90 Likes: 58
Rounding Down to the Nearest Decimal Point in C-Sh ...
Category: .Net 7

Question How do you Round Down the number to the nearest decimal point in C#? t ...


Views: 0 Likes: 51
C-Sharp (Learn About C-Sharp) Very Interesting Exp ...
Category: C-Sharp

C# documentation can be <a href="https//docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/index ...


Views: 294 Likes: 93
The content in the request produced errors while p ...
Category: .Net 7

Question How do you solve for an error in Asp.Net Core that says "The content in the request pr ...


Views: 0 Likes: 33
How to Deserialize XML into Object in Asp.Net Core ...
Category: .Net 7

Question How do you Deserialize XML String into a C# Object in Asp.Net Core 3.1? Answer ...


Views: 1336 Likes: 123
VBA Error Handling
Category: C-Sharp

Inside the VBA function declare (On Error GoTo Name) ...


Views: 319 Likes: 103
How to check if string is null before replacing ch ...
Category: SQL

Question How do you catch for nulls in a variable before calling String.Replace ...


Views: 382 Likes: 85
Neural Networks in C#
Category: Other

Neural network in C# using TensorFlow library. using Syst ...


Views: 0 Likes: 8
Print Error to Immediate VBA
Category: C-Sharp

For debugging VBA Access Database (Datamart), print errors to console <span style="color inherit; f ...


Views: 380 Likes: 102
InvalidOperationException: The 'Microsoft.AspNetCo ...
Category: Questions

Question How do you solve "InvalidOperationException The 'Microsoft-AspNetCor ...


Views: 495 Likes: 64
How to find out the Highest Number in an Array in ...
Category: .Net 7

Question How do you find out the highe ...


Views: 125 Likes: 69
What is New in C-Sharp 9 ( Developing Notes )
Category: C-Sharp

1. Instead of writing public class person, you now write public record p ...


Views: 260 Likes: 92
RuntimeBinderException: The best overloaded method ...
Category: .Net 7

Question How do you resolve the C-Sharp <a class='text-decoration-none' href='https//www.ernes ...


Views: 0 Likes: 33
Why is AspNet 6 System DateTime showing Chinese Ch ...
Category: .Net 7

Question Asp.Net 6 all of the sudden started showing dates in Chinese, what is ...


Views: 0 Likes: 32
Cannot create a DbSet for "MyModal" because this t ...
Category: .Net 7

Question I have no idea what is going on with this error. Yes, the error is qui ...


Views: 0 Likes: 31
The Best Way to Create an Interface in AspNet 6 (C ...
Category: .Net 7

1. Create your generic Interface like this and you will never regrete <span style="backgr ...


Views: 31 Likes: 33
InvalidOperationException: An exception was thrown ...
Category: Entity Framework

What is a LINQ Query?Linq which stands for Language Integrated Query ...


Views: 0 Likes: 69
Design Parterns in C-Sharp
Category: C-Sharp

Design Patterns (C#)< ...


Views: 366 Likes: 105
HTML Injection C-Sharp
Category: HTML5

When working with html inside code behind in asp.net, make sure the html tags have no spaces between ...


Views: 354 Likes: 102
Software Development Refactoring Wisdom I gained t ...
Category: Software Development

Software Development Refactoring Wisdom I gained through R ...


Views: 175 Likes: 84
Learn C-Sharp Programming Language
Category: C-Sharp

C# Program ...


Views: 375 Likes: 100
How to create PDF Signature Box using iTextSharp i ...
Category: .NET 7

&nbsp;I can suggest some popular libraries that might fit your needs 1. **iTextSharp** ...


Views: 0 Likes: 0
InvalidOperationException: Unable to resolve servi ...
Category: .Net 7

Question How do you solve Asp.Net 5 Error <span style="background-color #f8ca ...


Views: 217 Likes: 74
Short Cut for Creating Constructor in C-Sharp
Category: C-Sharp

It is very helpful when developing software to know the shortcut to implement code snippet. For exam ...


Views: 304 Likes: 86
An unhandled exception has occurred while executin ...
Category: .Net 7

Question Why is MemoryStream having a Null buffer even after checking if the Stream contains an ...


Views: 0 Likes: 36
Lazy Loading Objects in C-Sharp [Speed Complexity]
Category: C-Sharp

Dot Net Lazy Loading Class ...


Views: 304 Likes: 97
how to use speech in asp.net core
Category: .Net 7

Question How do you use Speech ...


Views: 268 Likes: 116
AspNet Core Performance Tuning and Best Practices ...
Category: .Net 7

C# Best Practices and Performance Tuning</ ...


Views: 140 Likes: 66
What is New in C-Sharp 9 Programming Language
Category: .Net 7

C# is one of the high-level programming languages, it is used in many business applications, Game ...


Views: 278 Likes: 102
Books for Programmers Manning.com
Category: Technology

Books for High-End Software DevelopersEarly in November 2018, I spoke with a ver ...


Views: 290 Likes: 107
VBA Error Handling
Category: C-Sharp

Inside the VBA function declare (On Error GoTo Name) ...


Views: 267 Likes: 107
Encountered end tag "div" with no matching start t ...
Category: .Net 7

Question Encountered end tag "div" with no matching start tag. Are your start/end tags properly ...


Views: 0 Likes: 45
VBA Microsoft Application Libraries
Category: C-Sharp

Nowadays it nearly impossible to avoid Microsoft's products. Therefore, it is always helpful to lear ...


Views: 252 Likes: 100
How to Code a Windows Service that Updates the Dat ...
Category: .Net 7

Question How do you write C-Sharp Code that runs as a Windows Background Service to update the D ...


Views: 0 Likes: 25
Asp.Net 5 Application is losing state when enters ...
Category: .Net 7

Question A C# Application is losing Application State e.g. IFeatureCollection, ...


Views: 196 Likes: 69
SQL Query Like does not work with Spaces in a Stri ...
Category: SQL

Question How do you get the TSQ ...


Views: 391 Likes: 82
What is Async Await in AspNet 6 (C-Sharp)
Category: .Net 7

Understanding Async Await in AspNet 6 1. After playing with Async Await ...


Views: 27 Likes: 73
A local or parameter named cannot be declared in t ...
Category: Technology

Problem When declaring a variable inside a using directive in C# (C-Sharp) you might get an erro ...


Views: 4416 Likes: 144
System.InvalidOperationException: 'FromSqlRaw' or ...
Category: .Net 7

Question How do you solve calling a store procedure in Asp.Net 5 C-Sharp 9 error "System.Invalid ...


Views: 306 Likes: 66
How to check if the number is empty in C-Sharp Asp ...
Category: HTML5

Question Is there a way to check if the number is empty in C#? There are so ma ...


Views: 0 Likes: 27
How to Write to PDF using an Open Source Library c ...
Category: .Net 7

Question How do I use the #PDF Library called iText 7 to write to the pdf in C-sharp?<br / ...


Views: 400 Likes: 93
How to Select only fields you care about from Elas ...
Category: Algorithms

Question How do you select only a few fields you want from Elasticsearch Query using C# in the ...


Views: 0 Likes: 66
How to Use Spans in C-Sharp ( Stackalloc, Heap and ...
Category: .Net 7

Read about Spans ...


Views: 145 Likes: 67
[Asp.Net Core 3.1] Zebra Printer SDK C# Unable to ...
Category: .Net 7

Question When programming with Zebra C-Sharp SDK and trying to implement code t ...


Views: 737 Likes: 72
[AspNet 6] Using Generic Types in an Interface MVC ...
Category: Questions

Question How do you inject an Interface with a generic Type defined? When try to inject the Inte ...


Views: 69 Likes: 54
C-Sharp Tutorials
Category: C-Sharp

Good Website for C# tutorials ...


Views: 358 Likes: 103
[C-Sharp] Base64 Image Decoding
Category: C-Sharp

Base64 Encoding ...


Views: 349 Likes: 101
PayPal Payment C-Sharp Doc
Category: Education

I ...


Views: 313 Likes: 124
nest - ElasticSearch Order By String
Category: .Net 7

Question How do you order by Date in Elasticsearch Nest C# API. Answer See the code bel ...


Views: 0 Likes: 40

Login to Continue, We will bring you back to this content 0



For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]