TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Compare Two String Using Compare Method in C#
Mukesh Kumar
Nov 28
2015
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
string str1 =
"my string"
;
string str2 =
"This is not my string"
;
if
(String.Compare(str1,str2) < 0)
{
// str1 is less than str2
Console.WriteLine(
"Yes"
);
}
else
if
(String.Compare(str1,str2) == 0)
{
// str1 equals str2
Console.WriteLine(
"Equals"
);
}
else
{
// str11 is greater than str2, and String.Compare returned a value greater than 0
Console.WriteLine(
"No"
);
}
C#
string