Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 18. Dynamic > The dynamic Type

18.2. The dynamic Type

C# 4.0 introduces a new type called dynamic. In some ways it looks just like any other type such as int, string, or FileStream: you can use it in variable declarations, or function arguments and return types, as Example 18-4 shows. (The method reads a little oddly—it’s a static method in the sense that it does not relate to any particular object instance. But it’s dynamic in the sense that it uses the dynamic type for its parameters and return value.)

Example 18-4. Using dynamic

static dynamic AddAnything(dynamic a, dynamic b)
{
    dynamic result = a + b;
    Console.WriteLine(result);
    return result;
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial