惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - Achilles.NET

路过 通过javascript获得当前窗口页面的宽高度 SQL SERVER设置重新构造字段值大小写敏感 - Achilles.NET - 博客园 修改SQL默认不区分大小写字段值规则 [转帖]Transact-SQL编程规范 Version 1.1 C#调用存储过程返回值 - Achilles.NET - 博客园 Ghost备份后找不到gho镜像文件的解决办法 GridView数据突出颜色显示解决办法 GridView中空记录不显示表头的解决方案[作者不祥] Temple js控制标题闪动 山西DOT NET俱乐部 WEB弹出窗口打印 打印脚本 DataGrid分页 妻子让老公死心塌地的绝招 下班无聊,随便YY const(C# 参考) ERP──Enterprise Resource Planning 企业资源计划系统
extern(C# 参考)
Achilles.NET · 2007-03-06 · via 博客园 - Achilles.NET

   extern修饰符用于声明在外部实现的方法。
   extern 修饰符的常见用法是在使用 Interop 服务调入非托管代码时与 DllImport 属性一起使用;在这种情况下,该方法还必须声明为 static,如下面的示例所示:
    [DllImport("avifil32.dll")]
    private static extern void AVIFileInit();

注意 
   extern 关键字还可以定义外部程序集别名,使得可以从单个程序集中引用同一组件的不同版本。
 将 abstract 和 extern 修饰符一起使用来修改同一成员是错误的。

使用 
   extern 修饰符意味着方法在 C# 代码的外部实现,而使用 abstract 修饰符意味着在类中未提供方法实现。注意 extern 关键字在使用上比在 C++ 中有更多的限制。
 
示例 
   在该示例中,程序接收来自用户的字符串并将该字符串显示在消息框中。程序使用从 User32.dll库导入的 MessageBox 方法。
using System; using System.Runtime.InteropServices;
class MainClass
{
 [DllImport("User32.dll")]
 public static extern int MessageBox(int h, string m, string c, int type);
 static int Main()
{
string myString;
 Console.Write("Enter your message: ");
 myString = Console.ReadLine();
return MessageBox(0, myString, "My Message Box", 0);
}
}
 此示例使用 C 程序创建一个 DLL,在下一示例中将从 C# 程序调用该 DLL。
// cmdll.c // compile with:
/LD int __declspec(dllexport) SampleMethod(int i)
{
 return i*10;
 }
该示例使用两个文件 CM.cs 和 Cmdll.c 来说明 extern。
C 文件是示例 2 中创建的外部 DLL,它从C# 程序内调用。
// cm.cs using System;
using System.Runtime.InteropServices;
public class MainClass {
 [DllImport("Cmdll.dll")]
public static extern int SampleMethod(int x);
 static void Main()
 {
Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(5));
}
}
输出SampleMethod() returns 50. 备注生成项目: 使用 Visual C++ 命令行将 Cmdll.c 编译为 DLL: cl /LD Cmdll.c 使用命令行编译 CM.cs: csc CM.cs 这将创建可执行文件 CM.exe。运行此程序时,SampleMethod 将值 5 传递到 DLL 文件,该文件将此值乘以 10 返回。