Compare two string in .net c#Devendra Kumar11yAsked Nov 27, 2015, 7:48 PM EST2 answersShareLinkedInXCopy linkSaveCompare two string value and then Passing Session
Compare two string in .net c#Devendra Kumar11yAsked Nov 27, 2015, 7:48 PM EST2 answersShareLinkedInXCopy linkSaveCompare two string value and then Passing Session
Ravi PatelRank #439 · 5.7K reputation11y agoPosted Nov 27, 2015, 8:56 PM EST0Hi, CodeCopystring a = "XXX"; string b = "YYY" ;CodeCopyif (a.Equals(b))CodeCopy{CodeCopySession["id"]=a;CodeCopy} 0
Mukesh KumarRank #119 · 18.2K reputation11y agoPosted Nov 27, 2015, 10:32 PM EST0Hi, You can use your as following way string str1 = "A string";string str2 = "Some other string";if(String.Compare(str1,str2) < 0){ // str1 is less than str2 Console.WriteLine("Yes");Session["mysession"]=str1; }else if(String.Compare(str1,str2) == 0){ // str1 equals str2 Console.WriteLine("Equals");Session["mysession"]=str1; }else{ // str11 is greater than str2, and String.Compare returned a value greater than 0 Console.WriteLine("No");Session["mysession"]=str1; } you can also use like this.. class Program{ static void Main() { string a = "a" + 1; string b = "a" + 1; // 1 // Compare a to b using instance method on a. if (a.Equals(b)) { Console.WriteLine("a.Equals(b) = true"); } // 2 // Compare b to a using instance method on b. if (b.Equals(a)) { Console.WriteLine("b.Equals(a) = true"); } // 3 // Compare a to b with op_Equality if (a == b) { Console.WriteLine("a == b = true"); } // 4 // Compare with string.Compare; this returns zero if they are equal if (string.Compare(a, b) == 0) { Console.WriteLine("string.Compare(a, b) = 0"); } // 5 // Compare with string.CompareOrdinal // This returns zero if the char numeric values are equal if (string.CompareOrdinal(a, b) == 0) { Console.WriteLine("string.CompareOrdinal(a, b) = 0"); } // 6 // Compare with instance Compare method if (a.CompareTo(b) == 0) { Console.WriteLine("a.CompareTo(b) = 0"); } }}and pass the session value as Session["mysession"]=yourstringvalue; hope this will help you.thanks 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ravi PatelRank #439 · 5.7K reputationPosted Nov 27, 2015, 8:56 PM EST
Mukesh KumarRank #119 · 18.2K reputationPosted Nov 27, 2015, 10:32 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts