string versus String !
-
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
-
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
-
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
They are the same. If you want to use reference try like this:
String someString = "";
DoSomething(ref someString);// Now someString has new value
Function:
private void DoSomething(ref String str)
{
str = "Was Empty";
} -
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
There is no difference.
string
is the C# alias toString
(which is reallySystem.String
). When the code compiles, all of yourstring
types are converted toSystem.String
in the IL. Personally, I prefer usingstring
when I am typing a variable andString
when I am acessing static members of the class. This is only personal preference as I think it makes the code easier to follow. There is nothing wrong with code like:bool empty = string.IsNullOrEmpty("");
instead of
bool empty = String.IsNullOrEmpty("");
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
They are the same. If you want to use reference try like this:
String someString = "";
DoSomething(ref someString);// Now someString has new value
Function:
private void DoSomething(ref String str)
{
str = "Was Empty";
}Why is the ref keyword added to String in this example. Isn't string a reference type already? I thought ref is only to make value types behave like reference types.
-
There is no difference.
string
is the C# alias toString
(which is reallySystem.String
). When the code compiles, all of yourstring
types are converted toSystem.String
in the IL. Personally, I prefer usingstring
when I am typing a variable andString
when I am acessing static members of the class. This is only personal preference as I think it makes the code easier to follow. There is nothing wrong with code like:bool empty = string.IsNullOrEmpty("");
instead of
bool empty = String.IsNullOrEmpty("");
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Glad to help.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
look over this file and tell me how are you thinking in improve it ! I spend an entire night at it. The idea is to have a MAP (on the paper) and rapidly look over it and "remember" what i must to put when I need it. it's like a pocket reminder(a very tiny little map). http://www.sendspace.com/file/p56n1r of course in time must be the answer....if any...hope so... :) thanks again.
-
There is no difference.
string
is the C# alias toString
(which is reallySystem.String
). When the code compiles, all of yourstring
types are converted toSystem.String
in the IL. Personally, I prefer usingstring
when I am typing a variable andString
when I am acessing static members of the class. This is only personal preference as I think it makes the code easier to follow. There is nothing wrong with code like:bool empty = string.IsNullOrEmpty("");
instead of
bool empty = String.IsNullOrEmpty("");
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Scott Dorman wrote:
I prefer using string when I am typing a variable and String when I am acessing static members of the class.
Me too, except I type
System.String
. -
string versus String ! I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses. I searched and find this piece of gold, but I don't know how to use it very well: Use "String" to refer specifically to the String class. Use "string" when referring to an object of the String class. How to use them, accordingly? thanks again.
-
Why is the ref keyword added to String in this example. Isn't string a reference type already? I thought ref is only to make value types behave like reference types.
humayunlalzad wrote:
Why is the ref keyword added to String in this example. Isn't string a reference type already? I thought ref is only to make value types behave like reference types.
I realy don't know about string, but i must have put into where i have struct type.
-
Why is the ref keyword added to String in this example. Isn't string a reference type already? I thought ref is only to make value types behave like reference types.
Hi, I suggest you run something similar to this:
string str="aha";
log(str);
func1(str);
log(str);
func2(ref str);
log(str);private void func1(String str) {str = "Changed"; log("1 "+str);}
private void func2(ref String str) {str = "Changed";log("2 "+str); }
private void log(string s) {Console.WriteLine(s);}and think about why it behaves the way it does. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Scott Dorman wrote:
I prefer using string when I am typing a variable and String when I am acessing static members of the class.
Me too, except I type
System.String
.as
System.Boolean.True
hasn't been provided, do you also typeSystem.Boolean.Parse(System.Boolean.TrueString)
instead oftrue
? :-DLuc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
as
System.Boolean.True
hasn't been provided, do you also typeSystem.Boolean.Parse(System.Boolean.TrueString)
instead oftrue
? :-DLuc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Don't tempt me; every once in a while I think about not using any of the aliases at all (they're all just syntactic sugar after all). Unfortunately they're required to specify base types for Enumerations :mad: .
-
Scott Dorman wrote:
I prefer using string when I am typing a variable and String when I am acessing static members of the class.
Me too, except I type
System.String
.I have great news for you:
System.String
System.String
System.String
The second one has "lang=none" in the CODE tag. :)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
I have great news for you:
System.String
System.String
System.String
The second one has "lang=none" in the CODE tag. :)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
I trust it is, however for harmless things like that, I just experiment a bit. I always allow for a few minutes of heuristics before taking the scientific route. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
I have great news for you:
System.String
System.String
System.String
The second one has "lang=none" in the CODE tag. :)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Yes, Chris enlightened me about that a day or two ago. I still say that text should be the default.