Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:05:04+00:00 2026-06-03T08:05:04+00:00

How to write a F# method equal to the below c# code? tried to

  • 0

How to write a F# method equal to the below c# code? tried to google it but couldn’t find any working ones. thanks.

public List<Tuple<long, string, string>> Fun(List<Tuple<long, string>> param)
{
  var ret = new List<Tuple<long, string, string>>();

  foreach (var tuple in param)
  {
    ret.Add(new Tuple<long, string, string>(tuple.Item1, tuple.Item2, "new val"));
  }

  return ret;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:05:05+00:00Added an answer on June 3, 2026 at 8:05 am

    If you want to use idiomatic functional lists, then you can write:

    let func (param:(int64 * string) list) = 
      [ for n, s in param -> n, s, "new val" ]
    

    I added the annotation (int64 * string) list to make sure that you get the same type as the one in your C#. If you didn’t add it, then the F# compiler would infer the function to be generic – because it actually does not matter what is the type of the first two elements of the tuple. The annotation can be also written in a C# style notation using param:list<int64 * string> which might be easier to read.

    If you wanted to use .NET List type (which is not usually recommended in F#), you can use the F# alias ResizeArray and write:

    let func (param:(int64 * string) ResizeArray) = 
      ResizeArray [ for n, s in param -> n, s, "new val" ]
    

    This creates an F# list and then converts it to .NET List<T> type. This should give you exactly the same public IL signature as the C# version, but I would recommend using F# specific types.

    As a side-note, the second example could be implemented using imperative F# code (using for to iterate over the elements just like in C#). This generates exactly the same IL as C#, but this is mainly useful if you need to optimize some F# code later on. So I do not recommend this version (it is also longer :-)):

    let func (param:(int64 * string) ResizeArray) = 
      let res = new ResizeArray<_>()
      for n, s in param do
        res.Add(n, s, "new val")
      res
    

    You could also use higher-order functions like List.map and write:

    let func (param:(int64 * string) list) = 
      params |> List.map (fun (n, s) -> n, s, "new val")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried the code below (the equal method is written after Programming in Scala
I'm trying to write a method like this: public static T Test<T>() { if
I wrote below code to compare to arrays that have same elements but in
The below code is my Method logic . pulic String getData() { if (leg.length
Numbers are randomly generated and passed to a method. Write a program to find
Hi I'm writing a write() method for my character driver and I was wondering
I have a class using ReaderWriterLockSlim with a read method and a write method
i write a method that loops through an array of buttons and checks if
How do you write a method/message with multiple parameters? EDIT: Like multiple parameters for
I wanted to write a method with an argument that defaults to a member

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.