Results 1 to 5 of 5

Thread: Declaring and calling extension method in C #

  1. #1
    Join Date
    Feb 2010
    Posts
    118

    Declaring and calling extension method in C #

    Hi all,

    I am .net programmer. I have a program but we are not able to any of the methods as the extension method . I need some declaring and calling extension method in C But It must be included in a non-nested, non-generic static class of them and therefore must be a static method. Please help. Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Declaring and calling extension method in C #

    Extension method itself can be generic, and can have return values, in addition to the first parameter, but also can contain ref / out parameters, can be used as partial part of a class, you can block them in the iteration to achieve. We approach the first parameter type is called extended type .
    Code:
    public static class StreamUtil123
    {
     const int BufferSize = 8102;
    
     public static void CopyTo (this Stream input,

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Declaring and calling extension method in C #

    You can use Call the extension method. Simply put, transformation of an instance of the code to use StreamUtil and transform the tool as simple classes. The following code uses we have suggested that a new "syntax" to call the CopyTo. I say "new" in fact it does not new because it is and we have been using exactly the same as calling an instance method syntax.

    Code:
    WebRequest request = WebRequest.Create ("http://mysite.com");
    Using (WebResponse response = request.GetResponse ())
    using (Stream responseStream = response.GetResponseStream ())
    using (FileStream output = File.Create ("response123.dat"))
    {
     responseStream.CopyTo (output);
    }
    In the above code, at least it looks like we let response flow to complete the copying operation. StreamUtil fact remains behind the completion of the actual work, but more natural reading of the code. Compiler behind the scenes is really only CopyTo call will be transferred to the right StreamUtil.CopyTo calls, and pass responseStream as a method of the first parameter.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Declaring and calling extension method in C #

    There were no special things that direct us in the end are now being called Stream extension method is still an instance of the conventional method. If you are using VS2008, when you MouseMove to a method call the above time, if it is an extension method, then there will be an obvious hints. Another smart tips will help you to indicate which method is to extend the method, a down arrow icon will appear in the extension method ago. Of course, we do not need to be carefully to observe every one way to understand it is not extended, because in most cases, we do not care that we are called in the end is an extension method, or an instance method.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Declaring and calling extension method in C #

    You will probably be calling extension methods far more often than implementing your own. Because extension methods are called by using instance method syntax, no special knowledge is required to use them from client code. To enable extension methods for a particular type, just add a using directive for the namespace in which the methods are defined. For example, to use the standard query operators, add this using directive to your code:

    Code:
    using System.Linq;
    Check and reply.

Similar Threads

  1. Spam from ibibo declaring me winner of 2 cars
    By Indrayan in forum Off Topic Chat
    Replies: 3
    Last Post: 03-09-2011, 07:45 AM
  2. Declaring interface in a Servlet
    By Kratos G in forum Software Development
    Replies: 3
    Last Post: 05-02-2011, 09:06 AM
  3. Memory Allocation Techniques for declaring objects
    By Gill_christ in forum Software Development
    Replies: 2
    Last Post: 04-05-2009, 07:21 PM
  4. Replies: 3
    Last Post: 25-02-2009, 10:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,719,083,958.87158 seconds with 17 queries