In C#, I've seen that some people use lower case string and sometimes String with Uppercase S. Is there any difference in using them?   string type = "Small";   String type  = "Large";
4602
Example (note the case):  string s = "Hello world!"; String s = "Hello world!";   What are the guidelines for the use of each? And what are the differences?
30627
In C# the Main class has string[] args parameter.  What is that for and where does it get used?
92333
if ('text'.equals(str))   or   if ('text' == str)   Is there any difference? If yes, then what is it?   Added, after answered.  String q = 'teXt'; system.debug('teXt'.equals(q)); // true system.debug('teXt' == q);      // true system.debug('text'.equals(q)); // false system.debug('text' == q);      // true
100659
Are there any problems with not prefixing private fields with an underscore in C# if the binary version is going to be consumed by other framework languages? For example since C# is case-sensitive you can call a field "foo" and the public property "Foo" and it works fine.  Would this have any effect on a case-insensitive language such as VB.NET, will there by any CLS-compliance (or other) problems if the names are only distinguishable by casing?
1339
console.log(&quot;double&quot;); vs. console.log('single'); I see more and more JavaScript libraries out there using single quotes when handling strings. What are the reasons to use one over the other? I thought they're pretty much interchangeable.
44916
What is the best way of doing case-insensitive string comparison in C++ without transforming a string to all uppercase or all lowercase?  Please indicate whether the methods are Unicode-friendly and how portable they are.
37260
In C# and in Java (and possibly other languages as well), variables declared in a "try" block are not in scope in the corresponding "catch" or "finally" blocks.  For example, the following code does not compile:  try {   String s = "test";   // (more code...) } catch {   Console.Out.WriteLine(s);  //Java fans: think "System.out.println" here instead }   In this code, a compile-time error occurs on the reference to s in the catch block, because s is only in scope in the try block.  (In Java, the compile error is "s cannot be resolved"; in C#, it's "The name 's' does not exist in the current context".)  The general solution to this issue seems to be to instead declare variables just before the try block, instead of within the try block:  String s; try {   s = "test";   // (more code...) } catch {   Console.Out.WriteLine(s);  //Java fans: think "System.out.println" here instead }   However, at least to me, (1) this feels like a clunky solution, and (2) it results in the variables having a larger scope than the programmer intended (the entire remainder of the method, instead of only in the context of the try-catch-finally).  My question is, what were/are the rationale(s) behind this language design decision (in Java, in C#, and/or in any other applicable languages)?
11638
Even nowadays I often see underscores in Java variables and methods, an example are member variables (like "m_count" or "_count"). As far as I remember, to use underscores in these cases is called bad style by Sun.  The only place they should be used is in constants (like in "public final static int IS_OKAY = 1;"), because constants should be all upper case and not camel case. Here, the underscore should make the code more readable.  Do you think using underscores in Java is bad style? If so (or not), why?
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
13157
Let's say that you want to output or concat strings. Which of the following styles do you prefer?   var p = new { FirstName = "Bill", LastName = "Gates" }; Console.WriteLine("{0} {1}", p.FirstName, p.LastName); Console.WriteLine(p.FirstName + " " + p.LastName);   Do you rather use format or do you simply concat strings? What is your favorite? Is one of these hurting your eyes?  Do you have any rational arguments to use one and not the other?  I'd go for the second one.
36269
In .NET why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision.
21112
Does the .NET String.Format method allow placement of a string at a fixed position within a fixed length string.   "           String Goes Here" "     String Goes Here      " "String Goes Here           "   How is this done using .NET?  Edit - I have tried Format/PadLeft/PadRight to death.  They do not work.  I don't know why. I ended up writing my own function to do this.  Edit - I made a mistake and used a colon instead of a comma in the format specifier.  Should be "{0,20}".  Thanks for all of the excellent and correct answers.
99569
Is there a way to write binary literals in C#, like prefixing hexadecimal with 0x? 0b doesn't work.  If not, what is an easy way to do it? Some kind of string conversion?
97311
Are there any documents out there that talk about proper formatting in apex? I have not been able to find too much on this subject (maybe my google skills are weak).  Some examples:   //comment with no space  // comment with space   if (something == something) { String foo = "keep it in one?"; }   if(something==something)       String foo="Or do it this way?";   I realize that this is probably based off of the user's preference, but I'm wondering if there is a standard to do things a certain way in apex? Would writing the syntax one way or the other affect the performance?
67471
Consider the following code:  void Handler(object o, EventArgs e) {    // I swear o is a string    string s = (string)o; // 1    //-OR-    string s = o as string; // 2    // -OR-    string s = o.ToString(); // 3 }   What is the difference between the three types of casting (okay, the 3rd one is not a casting, but you get the intent). Which one should be preferred?
78505
I'm asking with regards to c#, but I assume its the same in most other languages.  Does anyone have a good definition of expressions and statements and what the differences are?
12823
In .NET, what is the difference between String.Empty and "", and are they interchangable, or is there some underlying reference or Localization issues around equality that String.Empty will ensure are not a problem?