Skip to main content
deleted 2 characters in body
Source Link
Eric Lippert
  • 46.6k
  • 22
  • 93
  • 128

In C#, strings can be used like objects with methods, properties, and other features of objects.

In C# strings are objects with methods and properties.

At the same time, strings are treated the same as primitive data types like int or float in numerous ways as well (lowercase name, behaves like a keyword, etc.).

The C# specification used to have the word "primitive" in it. Twice. Never defined. Somehow used inconsistently even though it was only in there twice. We removed it from the specification. There is no such thing as a "primitive" type in C#, so there's really no way to answer questions about it.

The fact that string is an alias for System.String, and object is an alias for System.Object is just a fact about the specification of the language. There's no deeper meaning to suss out there. The fact that string and object are both reserved words is hardly relevant to the type system.

How does the C# string type act like an object and a primitive type simultaneously?

In C#, strings are objects. Integers are also objects. Floats are objects, decimals are objects. Whatever you think a "primitive type" is, there is no contradiction between anything acting like a "primitive type" and anything acting like an object. Objects act like objects because they are objects.

This is probably a deeply unsatisfying answer, but the question is very confusing. Can you sort out what you mean by "primitive type" and clarify the question?

 

In C#, strings can be used like objects with methods, properties, and other features of objects.

In C# strings are objects with methods and properties.

At the same time, strings are treated the same as primitive data types like int or float in numerous ways as well (lowercase name, behaves like a keyword, etc.).

The C# specification used to have the word "primitive" in it. Twice. Never defined. Somehow used inconsistently even though it was only in there twice. We removed it from the specification. There is no such thing as a "primitive" type in C#, so there's really no way to answer questions about it.

The fact that string is an alias for System.String, and object is an alias for System.Object is just a fact about the specification of the language. There's no deeper meaning to suss out there. The fact that string and object are both reserved words is hardly relevant to the type system.

How does the C# string type act like an object and a primitive type simultaneously?

In C#, strings are objects. Integers are also objects. Floats are objects, decimals are objects. Whatever you think a "primitive type" is, there is no contradiction between anything acting like a "primitive type" and anything acting like an object. Objects act like objects because they are objects.

This is probably a deeply unsatisfying answer, but the question is very confusing. Can you sort out what you mean by "primitive type" and clarify the question?

 

In C#, strings can be used like objects with methods, properties, and other features of objects.

In C# strings are objects with methods and properties.

At the same time, strings are treated the same as primitive data types like int or float in numerous ways as well (lowercase name, behaves like a keyword, etc.).

The C# specification used to have the word "primitive" in it. Twice. Never defined. Somehow used inconsistently even though it was only in there twice. We removed it from the specification. There is no such thing as a "primitive" type in C#, so there's really no way to answer questions about it.

The fact that string is an alias for System.String, and object is an alias for System.Object is just a fact about the specification of the language. There's no deeper meaning to suss out there. The fact that string and object are both reserved words is hardly relevant to the type system.

How does the C# string type act like an object and a primitive type simultaneously?

In C#, strings are objects. Integers are also objects. Floats are objects, decimals are objects. Whatever you think a "primitive type" is, there is no contradiction between anything acting like a "primitive type" and anything acting like an object. Objects act like objects because they are objects.

This is probably a deeply unsatisfying answer, but the question is very confusing. Can you sort out what you mean by "primitive type" and clarify the question?

Source Link
Eric Lippert
  • 46.6k
  • 22
  • 93
  • 128

In C#, strings can be used like objects with methods, properties, and other features of objects.

In C# strings are objects with methods and properties.

At the same time, strings are treated the same as primitive data types like int or float in numerous ways as well (lowercase name, behaves like a keyword, etc.).

The C# specification used to have the word "primitive" in it. Twice. Never defined. Somehow used inconsistently even though it was only in there twice. We removed it from the specification. There is no such thing as a "primitive" type in C#, so there's really no way to answer questions about it.

The fact that string is an alias for System.String, and object is an alias for System.Object is just a fact about the specification of the language. There's no deeper meaning to suss out there. The fact that string and object are both reserved words is hardly relevant to the type system.

How does the C# string type act like an object and a primitive type simultaneously?

In C#, strings are objects. Integers are also objects. Floats are objects, decimals are objects. Whatever you think a "primitive type" is, there is no contradiction between anything acting like a "primitive type" and anything acting like an object. Objects act like objects because they are objects.

This is probably a deeply unsatisfying answer, but the question is very confusing. Can you sort out what you mean by "primitive type" and clarify the question?