internal:對(duì)友元程序集和內(nèi)部可見.我們可以利用這一點(diǎn),使我們開發(fā)的類庫更加地安全.比如,你不喜歡你開發(fā)的ClassLib( DLL ),被其他公司或團(tuán)隊(duì)使用,就可以在使用internal , 當(dāng)然還要加上友元程序集的相關(guān)知識(shí).



上代碼:
TestFrendsAbb 類庫
ToolsBytes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestFrendsAbb.com
{
internal class ToolsBytes
{
private static ToolsBytes ins;
private static Object obj = 0;
internal static ToolsBytes Instance {
get {
if (ins == null)
{
lock (obj)
{
if (ins == null)
ins = new ToolsBytes();
}
}
return ins;
}
}
private ToolsBytes() { }
/// <summary>
/// 組合 addArr 和 src 將addArr放在src的前面并返回
/// </summary>
/// <param name="addArr">前</param>
/// <param name="src">后</param>
/// <returns></returns>
internal Byte[] addTop(Byte[] addArr, Byte[] src)
{
if (addArr != null && addArr.Length > 0)
{
Byte[] bc = null;
if (src != null)
{
bc = new Byte[addArr.Length + src.Length];
Buffer.BlockCopy(addArr, 0, bc, 0, addArr.Length);
Buffer.BlockCopy(src, 0, bc, addArr.Length, src.Length);
}
else
{
bc = new Byte[addArr.Length];
Buffer.BlockCopy(addArr, 0, bc, 0, addArr.Length);
}
return bc;
}
else
return src;
}
}
}Friend:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using TestFrendsAbb.com;
[assembly: InternalsVisibleTo("MCC")]
namespace TestFrendsAbb
{
internal class Friend
{
//public Byte[] addTop(Byte[] add, Byte[] src)
//{
// return ToolsBytes.Instance.addTop(add, src);
//}
internal Byte[] addTop2(Byte[] add, Byte[] src)
{
return ToolsBytes.Instance.addTop(add, src);
}
}
}MCC : 控制臺(tái)應(yīng)用程序
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MCC
{
class Program
{
static void Main(string[] args)
{
TestFrendsAbb.Friend fr = new TestFrendsAbb.Friend();
Byte[] by1 = BitConverter.GetBytes('胡');
Byte[] by2 = BitConverter.GetBytes('召');
Byte[] bytes = fr.addTop2(by1, by2);
StringBuilder sb = new StringBuilder();
sb.Append(BitConverter.ToChar(bytes, 0));
sb.Append(BitConverter.ToChar(bytes, 2));
Console.Write(sb);
Console.Read();
}
}
}Other:依然能調(diào)用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MCC.com
{
class Other
{
//Friend fr = new Friend();
TestFrendsAbb.Friend fr = new TestFrendsAbb.Friend();
}
}另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站標(biāo)題:C#友元程序集-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://www.chinadenli.net/article46/dcsceg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、網(wǎng)站導(dǎo)航、虛擬主機(jī)、網(wǎng)站建設(shè)、定制開發(fā)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容