I want to do this C# code in F#
string[] a = new string[5];
string b = string.Empty;
a[0] = "Line 1";
a[2] = "Line 2";
foreach (string c in a)
{
b = c + Environment.NewLine;
}
Its a lot better to use the built-in String.Join method than rolling your own function based on repeated string concatting. Here's the code in F#:
open System
let a = [| "Line 1"; null; "Line 2"; null; null;|]
let b = String.Join(Environment.NewLine, a)
The '^' operator concatenates two strings. Also, '+' is overloaded so it can work on strings. But using a StringBuilder or Join is a better strategy for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With