|
And now, is it important?
modified 19-Jan-21 21:04pm.
|
|
|
|
|
|
Could it be that you are confusing this with Java? .Net never had primitive types. One of the most important differences when the Java guys still dismissed c# as a bad copy of Java.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
Quote: Could it be that you are confusing this with Java? No. I never studied Java. I probably was just confusing it with.....
Get me coffee and no one gets hurt!
|
|
|
|
|
.Net really never had primitive types, but down below I just heard that the line between the classes and the aliases as value types is not drawn as clearly as I believed.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
I also prefer the differentiation, and I know other Code Projectors have said the same thing.
I dislike the aliases and I'd rather they weren't built in -- let the user define them as required.
What I find crazy is that when specifying the underlying type for an enumeration, you must use the alias.
And think I recall that there's a place where you mustn't use the alias.
|
|
|
|
|
PIEBALDconsult wrote: What I find crazy is that when specifying the underlying type for an enumeration, you must use the alias.
Not if you're using the Roslyn (C# 6 / VS2015) compiler:
enum Foo : Int32
{
Bar,
Baz,
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
No thanks. I prefer to write backward-compatible code unless there's a real reason to do otherwise.
|
|
|
|
|
There is a tiny difference, remember? Classes are reference types while the aliases are made to appear like value types for convenience.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
Classes are reference types but Int32 is a struct
|
|
|
|
|
That explains it. Then I'm right what String and string are concerned, but wrong about Int32 and int.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
CDP1802 wrote: Then I'm right what String and string are concerned
Nope again.
String and string are exactly the same - an immutable reference type.
The only reason you don't typically need to use new with a string is because the compiler has a deep knowledge of it.
string.cs - Reference Source[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Drat!
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
No, there is no difference.
|
|
|
|
|
Ok, then it's time to do some reading.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
In case I would ask same here...
It's really a two (at least) class community
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I've always used the lowercase string when declaring a type, but I use the uppercase String when calling static methods. For example:
string myString = "Hello World!";
string anotherString = String.Format("{0}", "Hola!");
Microsoft seems to do the same thing, as seen in some of their examples, like here.
|
|
|
|
|
If the usage is correct, that make me think why the VS Intellisense still display "name can be simplified", "Show potential fixes", IDE0001 C# Name can be simplified.
Isn't that "Show potential fixes" = there is a bug and here is the potential fix?
After all VS is Microsoft product right?
Bryian Tan
|
|
|
|
|
i'm getting "name can be simplified" since switching to VS2015 Community. (change String to string.)
|
|
|
|
|
Now that you have made up your mind, let me generate some doubts again.
It's no secret that value types don't really exist. They are classes, reference types, that are made to behave like value types by the compiler. You can use tham as reference types if you wish by working with the classes. If you want the value type behavior, you use the alias and the compiler does the rest.
The question which one to use is less a question of style. It's more a question of what you want to accomplish and strictly choosing one or the other limits your options without any real need.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
Are you sure you're not thinking of Java?
With .NET, there's no difference in behaviour between using the class name or the alias.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Don't think so, when was the last time you had to initialize an int with new() before using it or check for null? Now try that with Int32, which without question is the class that corresponds to int.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
|
I must admit that i have never tried to do that. Classes are reference types, (many) aliases are treated like value types. Always worked for me. Long ago I read a book when taking a look at .Net 1.0 and never had a need to question this.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
CDP1802 wrote: Classes are reference types, (many) aliases are treated like value types.
Nope. There is absolutely no difference between using the type name (Int32 ) and the alias (int ). They are exactly the same thing. They compile to the same IL.
int x = new int();
Int32 y = 42;
Console.WriteLine($"{x}, {y}");
Java differentiates between the primitive types and their reference type equivalents. In .NET, there is no difference.
It sounds like whoever wrote that book was confused, and managed to spread the confusion.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|