473,788 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extension Methods - first parameter ?

Hi, just learning extension methods and the first parameter confuses
me. I understand using the this keyword to indicate the class we wish
to extend, but is the first parameter also used to catch something
passed ? Or is is it just to specify the class we wish to extend?
the reason I guess I'm confused is because sometimes a see a variable
after the class name.

TIA
Gi
Jun 27 '08 #1
2 1265
On Mon, 21 Apr 2008 10:39:29 -0700, GiJeet <gi****@yahoo.c omwrote:
Hi, just learning extension methods and the first parameter confuses
me. I understand using the this keyword to indicate the class we wish
to extend, but is the first parameter also used to catch something
passed ? Or is is it just to specify the class we wish to extend?
The former. That's the point. An extension method looks like an instance
method when it's used. The first parameter of the method is the instance
on which the extension method was used. Just as you would access that
instance using "this" when writing an actual instance method in a class,
you use the named "this" argument (using the name, not the actual word
"this") to access that instance in code in an extension method.

See http://msdn2.microsoft.com/en-us/library/bb383977.aspx for more
details.

Pete
Jun 27 '08 #2
>The first parameter of the method is the instance
on which the extension method was used. Just as you would access that
instance using "this" when writing an actual instance method in a class,
you use the named "this" argument (using the name, not the actual word
"this") to access that instance in code in an extension method.
Ahh....got it now. Thanks!

G

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8034
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming language should support these so I'm sure that Python is no exception, but how can these be...
18
6958
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call...
4
1928
by: Marshal | last post by:
I think one of the major advancements on C# will be the growing support for Extension Methods and related concepts... The current syntax involves a static class with static members using a warping of the "this" concept applied to function parameters. Surely we'll see more twisting and warping of language semantics as this technology evolves... Rather than warp language symantics... It would be more apparently proper to allow something...
10
1766
by: John | last post by:
Trying to find out what is essential / optional, I made an extremely simple Class and Module combination to add two numbers. (see below) It appears that an empty constructor is needed n order to work right, although I quite don't see what is does in addition to the 2nd constructor. Also, the example works fine without message calls in either constructor (the numerical answer is still there and correct!). I exected it to no longer work...
3
1647
by: Deckarep | last post by:
I recently got into somewhat of a debate with a fellow co-worker. First I asked him if he new of a way to add a method to an existing class like enhancing a class but without using Inheritance. He asked, "Why on earth would you want to do this? Just inherit." I told him other dynamic languages can do this such as JavaScript where you can just add method to say the Array classes prototype chain. I told him I found this technique often...
25
3400
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
Hello, I'm having a discussion with my colleagues (and boss) over the use of static methods in a class. My colleagues say that static methods should be avoided whenever is possible, because their use slows down the application. For me, this sounds absurd - I believe that static methods should be used whenever they're necessary. However, I wasn't able to find any
8
1775
by: Steven Nagy | last post by:
Some simple yes/no questions. I tried googling first and couldn't find specific answers. These are related to .Net 3.5 extension methods 1) I found that I would like to add properties as well as methods. Is there such a thing as Extension Properties? 2) Can you add static extension methods to classes? The 'this' part implies an instance. For example, I'd like to be able to go: System.IO.File.MyCrazyMethod()
3
2103
by: raylopez99 | last post by:
The headline says it all. Great minds think alike: read the blog below from three years ago, as endorsed by Ritchie, who coinvented C. BTW the below lambda expression code will not work (.Where not recognized). I am using the 'standard' using directives using System;using System.Collections.Generic;using System.Diagnostics;using System.Text; And Visual Studio 2007.
3
4845
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately, due to a couple limitations of the language, MI is still not attainable (at least not succinctly). 1 - Interfaces cannot define data (only properties) 2 - Extension methods cannot be used to mix in property definitions (or implement interface...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.