Use the extensions method in C #2.0
I recently tested an FTP class and found that it cannot be compiled in. netcf V2, but it can be compiled in version 3.0. The error message is as follows:
Using system; using system. runtime. compilerservices; public static class extensions {public static datetime? Todatetime (this winapi. filetime time) {If (time. dwhighdatetime = 0) & (time. dwlowdatetime = 0) {return NULL;} uint dwlowdatetime = (uint) time. dwlowdatetime; long filetime = (time. dwhighdatetime <0x20) | dwlowdatetime; return New datetime? (Datetime. fromfiletimeutc (filetime ));}}
Later, I found out that it was in. netcf V3.0.Extension Method feature.One major purpose of extension method is to construct an auxiliary method.
To solve this problem, you can use either of the following methods:
Method 1: add the references of system. Core. DLL to the existing project. In this way, no errors are reported during compilation, and the test is normal. However, each project contains a system. Core. dll file, which is uncomfortable.
Method 2: add the following to the project:Code:
Namespace system. runtime. compilerservices {[attributeusage (attributetargets. Assembly | attributetargets. Class | attributetargets. Method)] public sealed class extensionattribute: attribute {}}
After the code is added, no error is reported during compilation and the code runs normally. You do not need to add the. netcf V3.0 system. Core. dll file.
During data query,Use C #3.0 extensions
Method"This articleArticleGood.