Dragno
Dragno

Reputation: 3124

Why in F# you can write String.Join but not string.Join?

In C# you can write string.Join and String.Join. But in F# you cannot write string.Join but only String.Join. Why is that? Is not string a type alias over .NET String class?

Upvotes: 5

Views: 91

Answers (1)

Phillip Carter
Phillip Carter

Reputation: 5005

In F# string, depending on where it's used, is a type alias or a function:

string 12 // this stringifies '12'

let f (s: string) = ... // here 'string' is a type alias for 'System.String'

And so static members like Join don't sit on string. They are available via String. If you created your own alias, then you'd get access to the static members via ..

In C#, both string and String refer to the same System.String at all times.

Upvotes: 11

Related Questions