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 5975951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:09:31+00:00 2026-05-22T21:09:31+00:00

The Real World Functional Programming has this code in page 65. The Tuple has

  • 0

The Real World Functional Programming has this code in page 65.

The Tuple has two properties Item1 and Item2, and it has TupleExtensions class as follows.

static class TupleExtensions {
  public static Tuple<T1, T2> WithItems2<T1, T2> 
    (this Tuple<T1, T2> tuple, T2 newItem2) { // line3 ???
      return Tuple.Create(tuple.Item1, newItme2); //  line4 ???
  }
}

var pragueOld = Tuple.Create("Prague", 1188000);
var pragueNew = pragueOld.WithItem2(pragueOld.Item2 + 13195);

The pragueOld.WithItem2() has only one parameter, but the definition has two parameters.

I think line 3, 4 is the same as this code.

(T2 newItem2) {
return Tuple.Create(this.Item1, newItem2)

What’s the meaning of this as is prepended in the first parameter? What advantages does this provides compared to the simple this.Item1 usage?

  • 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-05-22T21:09:32+00:00Added an answer on May 22, 2026 at 9:09 pm

    the this keyword, in this context, means that you are declaring an extension method.

    To declare an extension method you must be in the scope of a static class and the method must also be marked static.

    This would be an example

    namespace Utils
    {
        public static class StringExtension
        {
            public static int NonWhitespaceLength(this string text)
            {
                return text.Replace(" ","").Length;
            }
        }
    }
    

    and you could call this by either

    var a = "hello world ! !    !";
    
    Console.WriteLine(Utils.StringExtension.NonWhitespaceLength(a));
    

    or simply

    using Utils.StringExtension;
    
    var a = "hello world ! !    !";
    
    Console.WriteLine(a.NonWhitespaceLength());
    

    an additional note: the “this” parameter can actually be null. Which isn’t that intuitive and it took me a while to realize, so you can either expect the function to fail if null is passed, or add null reference checks, like so:

    namespace Utils
    {
        public static class StringExtension
        {
            public static int NonWhitespaceLength(this string text)
            {
                return text == null ? 0 : text.Replace(" ","").Length;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading the book Real-world functional programming by Tomas Petricek and Jon Skeet and
I'm at the moment reading the book Real world functional programming, and wondering how
I recently began to read some F# related literature, speaking of Real World Functional
NOTE: EDITED The real-world situation is a series of events that each have two
How would I go about creating a real world form creation class that I
Which dependently typed programming languages could be used for real world application development? These
Can someone give me a real-world scenario of a method/function with a string argument
I'm reading the Monads chapter in Real World Haskell (chapter 14). A function is
What real-world projects would you suggest looking through the sources? As I'm learning Java
What are real-world problems where a recursive approach is the natural solution besides depth-first

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.