Line structure F #

I want to make 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; } 
+4
source share
3 answers

Its much better to use the built-in String.Join method than wrapping your own function based on re-concatenating strings. Here is the code in F #:

 open System let a = [| "Line 1"; null; "Line 2"; null; null;|] let b = String.Join(Environment.NewLine, a) 
+14
source

The '^' operator concatenates two lines. In addition, the "+" is overloaded, so it can work with strings. But using StringBuilder or Join is the best strategy for this.

+2
source

You can use the F # concat from the System module, for example:

 let a = [| "Line 1"; null; "Line 2"; null; null;|] let b = String.concat System.Environment.NewLine a 

(you should not import the System namespace to avoid a name conflict between the F # String module and the .NET String class )

+2
source

All Articles