© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
7 replies
steven preadly

✅ Extension Methods

this is an extension method that i have read in the docs , my question is when i use this extension method as below code in that case the
this
this
keyword bind the sentence string inside method as i did not pass any parameter correct?
namespace StringExtnsion
{
    public static class WordCountExtinsion
    {
        //this is used to bind the method to the main class 
        public static int WordCount(this String str)
        {
            string[] strings = str.Split(new char[] { ' ' , '?' });

            return strings.Length;
        }
    }
}
namespace StringExtnsion
{
    public static class WordCountExtinsion
    {
        //this is used to bind the method to the main class 
        public static int WordCount(this String str)
        {
            string[] strings = str.Split(new char[] { ' ' , '?' });

            return strings.Length;
        }
    }
}

string? sentence = "My Name Is Mina?mina";

Console.WriteLine(sentence.WordCount());
string? sentence = "My Name Is Mina?mina";

Console.WriteLine(sentence.WordCount());
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Extension Methods
C#CC# / help
2y ago
scope of using statements and extension methods
C#CC# / help
4y ago
✅ methods
C#CC# / help
8mo ago
✅ Methods
C#CC# / help
16mo ago