Click here to Skip to main content
15,390,899 members
Home / Discussions / C#
   

C#

 
AnswerRe: Command Binding Pin
Gerry Schmitz24-Jun-16 4:21
mveGerry Schmitz24-Jun-16 4:21 
AnswerRe: Command Binding Pin
Bernhard Hiller26-Jun-16 21:11
MemberBernhard Hiller26-Jun-16 21:11 
AnswerRe: Command Binding Pin
Pete O'Hanlon26-Jun-16 22:00
mvaPete O'Hanlon26-Jun-16 22:00 
QuestionDataGridViewCheckBoxColumn Checkig Problem Pin
Member 1209010423-Jun-16 20:17
MemberMember 1209010423-Jun-16 20:17 
SuggestionRe: DataGridViewCheckBoxColumn Checkig Problem Pin
CHill6024-Jun-16 0:10
mveCHill6024-Jun-16 0:10 
Questionwhy extension method is required in c#? Pin
Member 1031806523-Jun-16 18:36
MemberMember 1031806523-Jun-16 18:36 
AnswerRe: why extension method is required in c#? Pin
PIEBALDconsult23-Jun-16 18:40
professionalPIEBALDconsult23-Jun-16 18:40 
AnswerRe: why extension method is required in c#? PinPopular
OriginalGriff23-Jun-16 20:40
mveOriginalGriff23-Jun-16 20:40 
Extension methods aren't "required" they are just a "little sugar" which makes things work a little more nicely. They provide a mechanism to add methods to a class without deriving from it.
For example, if you have an extension method to remove all the vowels from a string:
C#
public static class ExtensionMethods
    {
    private const string vowels = "aeiouAEIOU";
    public static string RemoveVowels(this string inp)
        {
        StringBuilder sb = new StringBuilder(inp.Length);
        foreach (char c in inp)
            {
            if (!vowels.Contains(c)) sb.Append(c);
            }
        return sb.ToString();
        }
    }
Then you can call it as if it was a part of the string class:
C#
string noVowels = "The quick brown fox jumps over the lazy dog.".RemoveVowels();

And since string is a sealed class, you can't derive from it - so an extension method is the only way to do that.
But...you don't have to use an extension method - you could write it as a "normal" method.
C#
public static class GeneralMethods
    {
    private const string vowels = "aeiouAEIOU";
    public static string RemoveVowels(string inp)
        {
        StringBuilder sb = new StringBuilder(inp.Length);
        foreach (char c in inp)
            {
            if (!vowels.Contains(c)) sb.Append(c);
            }
        return sb.ToString();
        }
    }
But then, you have to call it as a "normal method:
C#
string noVowels = GeneralMethods.RemoveVowels("The quick brown fox jumps over the lazy dog.");

Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: why extension method is required in c#? Pin
PIEBALDconsult24-Jun-16 3:35
professionalPIEBALDconsult24-Jun-16 3:35 
QuestionUse one dimensional array with RDotNet in C# Pin
Member 1085025323-Jun-16 8:30
MemberMember 1085025323-Jun-16 8:30 
QuestionUpdate SQL table using CLR Pin
IT - Researcher22-Jun-16 21:38
MemberIT - Researcher22-Jun-16 21:38 
QuestionRe: Update SQL table using CLR Pin
Gerry Schmitz23-Jun-16 12:44
mveGerry Schmitz23-Jun-16 12:44 
AnswerRe: Update SQL table using CLR Pin
IT - Researcher23-Jun-16 18:56
MemberIT - Researcher23-Jun-16 18:56 
GeneralRe: Update SQL table using CLR Pin
Gerry Schmitz24-Jun-16 3:44
mveGerry Schmitz24-Jun-16 3:44 
QuestionProgrammatically Change Windows Photo View Language Pin
Kevin Marois22-Jun-16 13:24
professionalKevin Marois22-Jun-16 13:24 
GeneralRe: Programmatically Change Windows Photo View Language Pin
Pete O'Hanlon22-Jun-16 21:31
mvaPete O'Hanlon22-Jun-16 21:31 
AnswerRe: Programmatically Change Windows Photo View Language Pin
Bernhard Hiller22-Jun-16 22:04
MemberBernhard Hiller22-Jun-16 22:04 
QuestionI need some help using Exchange EWS with C# Pin
turbosupramk322-Jun-16 12:02
Memberturbosupramk322-Jun-16 12:02 
AnswerRe: I need some help using Exchange EWS with C# Pin
Dave Kreskowiak22-Jun-16 12:52
mveDave Kreskowiak22-Jun-16 12:52 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk322-Jun-16 13:03
Memberturbosupramk322-Jun-16 13:03 
GeneralRe: I need some help using Exchange EWS with C# Pin
Dave Kreskowiak22-Jun-16 17:56
mveDave Kreskowiak22-Jun-16 17:56 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk323-Jun-16 4:41
Memberturbosupramk323-Jun-16 4:41 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk323-Jun-16 5:05
Memberturbosupramk323-Jun-16 5:05 
QuestionVS2015 designer resizes my main form on different development PCs Pin
LenHodder22-Jun-16 6:53
MemberLenHodder22-Jun-16 6:53 
AnswerRe: VS2015 designer resizes my main form on different development PCs Pin
BillWoodruff22-Jun-16 18:12
mveBillWoodruff22-Jun-16 18:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.