Check if two strings are permutation of each other | C # program to check whether two strings are Permutations of each other ; function to check whether two strings are Permutation of each other ; Get lengths of both strings ; If length of both strings is not same , then they cannot be Permutation ; Sort both strings ; Compare sorted strings ; Driver code
using System ; class GfG { static bool arePermutation ( String str1 , String str2 ) { int n1 = str1 . Length ; int n2 = str2 . Length ; if ( n1 != n2 ) return false ; char [ ] ch1 = str1 . ToCharArray ( ) ; char [ ] ch2 = str2 . ToCharArray ( ) ; Array . Sort ( ch1 ) ; Array . Sort ( ch2 ) ; for ( int i = 0 ; i < n1 ; i ++ ) if ( ch1 [ i ] != ch2 [ i ] ) return false ; return true ; } public static void Main ( String [ ] args ) { String str1 = " test " ; String str2 = " ttew " ; if ( arePermutation ( str1 , str2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }