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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:14:33+00:00 2026-05-22T18:14:33+00:00

I have a weird question. Here it goes – Let’s consider the below code

  • 0

I have a weird question. Here it goes –

Let’s consider the below code snippet:

string test ="this is a test string";
Console.WriteLine(test);

I want it to print a different thing – like yup, this is a test string. Actually, I want to see if the string is matching some pattern, and if so I want it printed differently. I want that to be the case only when I am printing it to console, but whenever I am using it elsewhere, it should be the original one.

I was hoping I could write an extension method on String class ( or Object class? ) and make ToString() return as per my needs, but the docs say:

An extension method will never be
called if it has the same signature as
a method defined in the type.

Is there any possibility of doing such a thing? I cannot use a new type. Or maybe trying to make ToString() behave differently is not the way to go. But is there a way to make a particular string print to the console differently but be used in its original form elsewhere?

  • 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-22T18:14:34+00:00Added an answer on May 22, 2026 at 6:14 pm

    You could do something like this:

    public static class StringExtension
    {
        public static void WriteToConsole(this string text)
        {
            string result;
            if (<matches1>)
                result = "111";
            else if (<matches1>)
                result = "222";
            Console.WriteLine(result);
        }
    }
    

    And the usage would be:

    string test = "this is a test string";
    test.WriteToConsole();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi this may seem like a weird question, but here's my situation: I have
Alright, I have some weird behavior and this question goes to the people out
Weird question but here goes... I have a webpage and i want to get
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
OK, this is a slightly weird question. We have a touch-screen application (i.e., no
OK, this may sound weird, but here goes. There are 2 computers, A (Pentium
I don't know if this is strictly a programming question but here goes. I
Strange Question i guess but i have this bit of code in my page...
This is a weird requirement I have. I know even my question is quite
This is a little bit of weird problem here. Say I have a C++

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.