In C#, you can initialize a list like so:
var list = new List<int> { obj1, obj2, obj3 };
I was expecting to do something similar in F# but keep getting errors:
let list = { obj1, obj2, obj3 }
Is this possible in F#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To create an (immutable) F# list, you can write:
There is a number of other options. You can create arrays by using
[| .. |]instead of[ .. ]and you can also write sequence expressions that allow you to generate data – similarly to C# iterator methods. For more information, refer to: