Results 1 to 6 of 6

Thread: Extension methods in C# 3.0

  1. #1
    Join Date
    Feb 2010
    Posts
    173

    Extension methods in C# 3.0

    Hi all,

    I am a programming software C# 3.0 newly. I heard that a new Supplementary features can be considered are aimed at the development of LINQ to LINQ easier to use, created some of the new features, of course, these new features can also be non - LINQ-related features are used. Can anybody have any idea about the Extension methods in C# 3.0. Please reply.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Extension methods in C# 3.0

    Extension methods defined, require attention in three parts: a static class (private public can be); two static methods (private-public can be); and a pre-function arguments with this (must be the first parameter ago)
    Code:
    namespace my name.lastname
    {
    static class MyExtensionMethods123
    {
    internal static void Print (this object s)
    {
    Console.WriteLine (s);
    }
    }
    }

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

    Re: Extension methods in C# 3.0

    My Extension methods used points to note: using namespace where you defined.

    Code:
    using myname.G123;
    
    static void Main (string [] args)
    {
    object o = "follow";
    o.Print ();
    }
    Such a very simple code, we can very easily against the open-source third-party controls that do not increase the additional needs many of our own features.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Extension methods in C# 3.0

    We look at some special cases, through the analysis of these special circumstances, we can better understand extension methods like extended class way as the original method when the processing logic. We are not a third-party open source components of a class extends a method, such as method: Print. After a period of time, this third party has released a new version of the component, such an increase in the Print method.

    Code:
    namespace name.book
    {
    
    public class MyClass123
    {
    public void Print ()
    {
    Console.WriteLine ("****");
    }
    }
    static class MyExtensionMethods123
    {
    internal static void Print (this MyClass123 s)
    {
    Console.WriteLine123 ( "hi" + s.ToString ());
    }
    }

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Extension methods in C# 3.0

    The extension method with the method of the class conflict of the time, the compiler does not report the use of any error, this time to a class method of highest priority, when we use the method of the class, rather than extension methods. There are so many types of other extension methods is also present in the C# 3.0. Check that and reply.

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

    Re: Extension methods in C# 3.0

    For instance, I am using the following extension method in C#3.0


    Code:
    namespace myname.any
    {
    static class MyExtensionMethods123
    {
    public static int Test0123 (this int i)
    {
    return i * 4;
    }
    
    public static int Test023 (this int i)
    {
    return i + 9;
    }
    }
    }

Similar Threads

  1. Replies: 4
    Last Post: 20-07-2010, 06:32 AM
  2. What is Abstract methods?
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 11:59 AM
  3. Get and Set methods
    By garfield1 in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 02:20 PM
  4. use of methods and constructor
    By beelow in forum Software Development
    Replies: 4
    Last Post: 14-11-2009, 01:37 AM

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,713,998,337.28123 seconds with 16 queries