TheSwamp
Code Red => .NET => Topic started by: A_LOTA_NOTA on March 06, 2008, 01:49:39 PM
-
I'm sure this is something simple that I'm missing. This is an exaple I found for "Sting.Compare" but I can't get it to compile.
public class Test
{
// The program begains inside Main
public static void Main()
{
//code goes here
string s1 = "Jon";
string s2 = "Jonny";
if (String.Compare (s1 , s2) < 0)
System.Console.Out.WriteLine(s1 + " comes before " + s2);
}// end of main
}// end of Test
Thanks for the help!
-
C# is case sensitive, so String.Compare is not equal to string.Compare.
This might be better placed in the .Net forum.
-
C# is case sensitive, so String.Compare is not equal to string.Compare.
That did it!! Thanks!!
-
C# is case sensitive, so String.Compare is not equal to string.Compare.
That did it!! Thanks!!
Glad it worked, you're welcome.
-
Actually String and string are functionally the same .. string is aliased from String ..
a piccy ... it compiles for me .
-
Actually String and string are functionally the same .. string is aliased from String ..
a piccy ... it compiles for me .
You are correct. I just tried it in one of my routines, and it compiled also. I don't know why it worked for the OP then. Maybe it fixed something else in the code. Thanks for the heads up Kerry.
-
Actually String and string are functionally the same .. string is aliased from String ..
a piccy ... it compiles for me .
You are correct. I just tried it in one of my routines, and it compiled also. I don't know why it worked for the OP then. Maybe it fixed something else in the code. Thanks for the heads up Kerry.
I changed the "S" in String.Compare to lower case & it compiles. Then I change it back to upper case I get "Test.cs(11,7): error CS0103: The name 'String' does not exist in the current context
-
Perhaps try adding
using System;
or using fully qualified name System.String.Compare.....
-
As has been said above, C# is a CASE SENSITIVE language and also to add a 'using' directive for 'System' in your code, as your use of System.Console.Out.Writeline indicates you have not.
However, it goes a bit deeper than has already been said. C# defines aliases for the CTS's (Common Type System) datatypes. So, for example, 'int' in C# is actually an alias for the CTS type System.Int32 as is 'string' an alias for System.String.
So, as Dave mentioned above, you would have to have a using declaration for System (using System;) at the head of your code file, OR, use fully qualified CTS types in your code (which I would NOT recommend).
If you were to NOT use the using system declaration, you would have to write System.String.Compare(yada yada)...which will make your code harder to read.
Cheers,
Glenn.