Click here to Skip to main content
15,892,927 members
Home / Discussions / C#
   

C#

 
QuestionMVC Pin
Pramod Singh (C)21-May-14 2:34
professionalPramod Singh (C)21-May-14 2:34 
AnswerRe: MVC Pin
Kornfeld Eliyahu Peter21-May-14 2:50
professionalKornfeld Eliyahu Peter21-May-14 2:50 
GeneralRe: MVC Pin
Pramod Singh (C)21-May-14 18:59
professionalPramod Singh (C)21-May-14 18:59 
AnswerRe: MVC Pin
Keith Barrow21-May-14 2:58
professionalKeith Barrow21-May-14 2:58 
GeneralRe: MVC Pin
Pramod Singh (C)21-May-14 18:57
professionalPramod Singh (C)21-May-14 18:57 
QuestionC# Pin
Pramod Singh (C)21-May-14 2:04
professionalPramod Singh (C)21-May-14 2:04 
AnswerRe: C# Pin
V.21-May-14 2:24
professionalV.21-May-14 2:24 
AnswerRe: C# PinPopular
Pete O'Hanlon21-May-14 2:29
mvePete O'Hanlon21-May-14 2:29 
An extension method is a piece of code that allows you to extend a type with custom functionality. This feature was introduced alongside LINQ. Suppose you wanted to add the ability to check whether or not an integer was within a certain range, you would declare a static method inside a static class (this is required for extension methods), that passed in the parameter in a special way. Here's this example
C#
public static class IntegerExtensions
{
  public static bool Between(this int value, int startRange, int endRange) // Note the special "this" word. That's the thing that says this is an extension method
  {
    return value >= startRange && value <= endRange;
  }
}
To call this you would do something like this:
C#
int checker = 10;
if (checker.Between(0, 50)
{
  Console.WriteLine("I'm in the range");
}
Now, if you want to use the extension method, you have to make sure that the namespace for the static class is included in the file that you are calling the extension from. Also, there's nothing to stop you writing this code as well
C#
if (IntegerExtensions.Between(checker, 0, 50))
Ultimately they resolve to the same thing.
GeneralRe: C# Pin
Richard MacCutchan21-May-14 22:04
mveRichard MacCutchan21-May-14 22:04 
GeneralRe: C# Pin
Pete O'Hanlon21-May-14 23:14
mvePete O'Hanlon21-May-14 23:14 
Questionsaving necessery point from a curve Pin
maysamfth20-May-14 18:56
maysamfth20-May-14 18:56 
AnswerRe: saving necessery point from a curve Pin
V.20-May-14 21:36
professionalV.20-May-14 21:36 
GeneralRe: saving necessery point from a curve Pin
maysamfth22-May-14 7:54
maysamfth22-May-14 7:54 
Questionoffline wikipidia Pin
Member 1075034520-May-14 6:42
Member 1075034520-May-14 6:42 
AnswerRe: offline wikipidia Pin
Pete O'Hanlon20-May-14 6:45
mvePete O'Hanlon20-May-14 6:45 
QuestionHow can I add standalone="no" in creating an XML file? Pin
Member 1063699820-May-14 4:13
Member 1063699820-May-14 4:13 
AnswerRe: How can I add standalone="no" in creating an XML file? Pin
thatraja20-May-14 5:30
professionalthatraja20-May-14 5:30 
GeneralRe: How can I add standalone="no" in creating an XML file? Pin
Member 1063699820-May-14 6:03
Member 1063699820-May-14 6:03 
GeneralRe: How can I add standalone="no" in creating an XML file? Pin
thatraja20-May-14 23:10
professionalthatraja20-May-14 23:10 
GeneralRe: How can I add standalone="no" in creating an XML file? Pin
Member 1063699821-May-14 4:37
Member 1063699821-May-14 4:37 
AnswerRe: How can I add standalone="no" in creating an XML file? Pin
Francine DeGrood Taylor20-May-14 13:16
Francine DeGrood Taylor20-May-14 13:16 
GeneralRe: How can I add standalone="no" in creating an XML file? Pin
Member 1063699821-May-14 4:33
Member 1063699821-May-14 4:33 
Questionwhich is the best way Pin
Srikanth95420-May-14 2:03
Srikanth95420-May-14 2:03 
AnswerRe: which is the best way Pin
OriginalGriff20-May-14 2:32
mveOriginalGriff20-May-14 2:32 
NewsAnyone Aware of this URI from MSDN Pin
cpquest20-May-14 1:03
cpquest20-May-14 1:03 

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.