Click here to Skip to main content
15,900,495 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
simple querstion:

C#
string a="1" (string)
string b="2" (string)


I want to know which is bigger؟

Without use(Convert or int.tryParse)
in c#??

--------------------------------------
Delphi seven it was possible
Delphi
in delphi:
if('1'<='2')
begin  
end
Posted
Updated 24-Nov-14 21:50pm
v2
Comments
BillWoodruff 25-Nov-14 8:22am    
Not clear if you are asking how to compare the integer values of two instances of 'char, or if you are asking how to compare the numeric values of two numbers encoded as 'string where there could be more than one character per string.

In other words: do you also want to evaluate something like "100" and "103" ?

Aren't those characters you're using in Delphi?

In .NET you can use those two methods, to check the integer representation of the string. But, lets change them to characters, and you'll see that this same method works here too.

C#
// condition...
if('1' <= '2') {
   // what to do
   Console.WriteLine("Works");
}


.. above code printed "Works" in the Console, here[^] give it a try yourself.

You can use them as variables too, such as

C#
// variable initialization and declaration
char a = '1';
char b = '2';
// condition
if(a <= b) {
   // what to do...
   Console.WriteLine("Works");
}


Wasn't it unfair of you, to use strings and not use Convert or Int.TryParse? Try this dotnetperl[^] link for more.
 
Share this answer
 
v2
Comments
BillWoodruff 25-Nov-14 9:35am    
Think about this:

char a = 'a';
char b = 'B';

bool isNum = a == 97; // true
bool isGt = b > a; // false
hi, hope this link will help to solve your query :

http://www.dotnetperls.com/string-compare[^]
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 25-Nov-14 3:57am    
The thing is that he used characters in delphi and used strings in the .NET. Converting those strings into characters works as required in .NET too.

See my answer "Solution 2" for more on this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900