C# 中的元數(shù)據(jù)
Sep 03, 2024 pm 03:30 PM元資料中的 C# 被定義為描述我們的程式的二進(jìn)位訊息,該資訊要么存儲(chǔ)在公共語言運(yùn)行時(shí)可移植可執(zhí)行檔中,要么存儲(chǔ)在內(nèi)存中。如果您從可移植執(zhí)行檔編譯程式碼,則元資料將插入檔案的另一個(gè)區(qū)域部分,所有這些程式碼現(xiàn)在將轉(zhuǎn)換為 MSIL 格式(Microsoft 中間語言),然後程式碼移至檔案的另一個(gè)分割部分。程式集中定義和引用的所有資料類型和資料成員都放在元資料中。當(dāng)我們在運(yùn)行時(shí)執(zhí)行 C# 程式碼時(shí),它會(huì)從記憶體中載入元資料。 C#元資料的主要目的是了解類別的類別、資料成員、繼承、資料類型等資訊。文件中的元資料由表和堆資料結(jié)構(gòu)組成。
元資料的使用
以下是元資料的用途:
- 它提供了有關(guān)程序集資料類型的描述,如名稱、可見性、基類和介面等
- 它提供了方法、欄位、屬性、事件和巢狀類型等資料成員。
- 它也提供了修改類型和成員的元素的附加描述。
- 它具有名稱、版本、公鑰等身分。
- 它是簡單程式設(shè)計(jì)模型的關(guān)鍵,它將消除 IDL(介面定義語言)檔案、頭檔的必要性。
元資料型別
元資料型別如下圖:
元資料的作用
元資料的作用如下:
元資料在 C# 中如何運(yùn)作?
C# 元資料可以了解有關(guān)資料的資料。
文法:
using packageName;//used for insert the packages in C# public class MyApp { public static int Main() { //data types Console.WriteLine("Required Message"); } //user defined methods for other logics }
C# 中的元資料範(fàn)例
下面給出了 C# 中元資料的範(fàn)例:
範(fàn)例#1
3 個(gè)數(shù)字的乘法
代碼:乘法.cs
using System; //Used for declaring the package or used for importing existed packege public class Multiplication//declaring the class { public static int Main ()// main method for displaying the output { //declaring and defining the varaiables int x = 50; int y = 20; int z=30; //Printing the output of the multiplication of 2 numbers Console.WriteLine ("Multiplication of {0},{1} and {2} is {3}",x,y,z,multiplication(x,y,z)); return 0; } public static int multiplication(int x, int y, int z)// multiplication() method implemention { return (x * y*z);// return multiplication of 3 numbers } }
輸出:
說明:
- 正如您在「關(guān)於」中看到的那樣,您可以看到實(shí)際數(shù)據(jù),如果我們想要元數(shù)據(jù)或二進(jìn)位數(shù)據(jù),我們可以在機(jī)器生成的程式碼中看到編譯器,這些程式碼始終是加密的,人類無法理解它。
範(fàn)例#2
正方形面積
代碼:SquareOfArea.cs
using System; //Used for declaring the package or used for importing existed packege public class SquareArea//declaring the class { public static int Main ()// main method for displaying the output { //declaring and defining the varaiables int x = 50; //Printing the output of the areaOfSquare Console.WriteLine ("Area of Square is {0}",areaOfSquare(x)); return 0; } public static int areaOfSquare(int x)// multiplication() method implemention { return (x*x);// return area Of Square } }
輸出:
說明:
- 正如您在「關(guān)於」中看到的那樣,您可以看到實(shí)際數(shù)據(jù),如果我們想要元數(shù)據(jù)或二進(jìn)位數(shù)據(jù),我們可以在機(jī)器生成的程式碼中看到編譯器,這些程式碼始終是加密的,人類無法理解它。
範(fàn)例#3
多個(gè)帶有資料的類別
程式碼:MultiData.net
using System; //Used for declaring the package or used for importing existed packege using System.Collections.Generic; //Used for declaring the package or used for importing existed packege public class Entity {//declaring the class //setters and getters for set and get the data public string Name {get;set;} public string Uses {get;set;} //toString method to overide predefined String data public override string ToString() { string output1=string.Format("My Name is {0}", Name); string output2=string.Format(" He is: {0}", Uses); return output1+output2; } } //declaring interface with reference class extention public interface IMeta<T> where T: class { //setters and getter for set and get the data T Inner {get;set;} stringMetaData {get;set;} } //declaring interface with reference class extention public interface IStorage<T> where T: class { //method definition for save the data T Save(); } //declaring the class by extending Imeta and IStorage interfaces public class Meta<T> : IMeta<T>, IStorage<T> where T: class { //creating a generic dictionary variable private static Dictionary<T, Meta<T>> _stash = new Dictionary<T, Meta<T>>(); //constructor for the class public Meta(T item) { Inner = item; } //setters and getters for set and get the data public T Inner {get;set;} public string MetaData {get;set;} //method implementation for operator public static implicit operator T(Meta<T> meta) { if (! _stash.ContainsKey(meta.Inner)) _stash.Add(meta.Inner, meta); returnmeta.Inner; } public static implicit operator Meta<T>(T item) { try { return _stash[item]; } catch { return null; } } //save the data to repository public T Save() { return this; } } //declaring the class public static class MetaHelper { //method definition for return the data public static IMeta<T>GetMeta<T>(T item) where T: class { return (Meta<T>)item; } //method definition for store the data public static IStorage<T>GetStorage<T>(T item) where T: class { return (Meta<T>)item; } } //declaring the class public class Program { //Entity type for createEntity method definition with 2 arguments public static Entity CreateEntity(string name, string uses) { //creating a variable var result = new Meta<Entity>(new Entity(){ Name = name, Uses = uses }); //adding data to the variable that is metadata result.MetaData = "Paramesh"; return? result; } //test method to test the data public static void Main() { //Passing the values to createEntity method varent = CreateEntity("Amardeep", "Good Person"); //types casting ent into Meta class Meta<Entity> meta = (Meta<Entity>)ent; //creating variables varimeta = MetaHelper.GetMeta<Entity>(ent); varistore = MetaHelper.GetStorage<Entity>(ent); var stored = istore.Save(); //Displaying output Console.WriteLine("MetaData: {0} {1} {2} {3}", imeta.MetaData, imeta.Inner.Name, stored.Name, stored.Uses); Console.WriteLine(ent); if (meta != null) Console.WriteLine(meta.MetaData); elseConsole.WriteLine("This is not a meta type"); } }
輸出:
說明:
- 正如您在「關(guān)於」中看到的那樣,您可以看到實(shí)際數(shù)據(jù),如果我們想要元數(shù)據(jù)或二進(jìn)位數(shù)據(jù),我們可以在機(jī)器生成的程式碼中看到編譯器,這些程式碼始終是加密的,人類無法理解它。
結(jié)論
C#中的元資料用於了解資料的相關(guān)資訊。這些都是加密成二進(jìn)位格式的,這是人類無法理解的,這就是為什麼我們將二進(jìn)位代碼轉(zhuǎn)換為正常程式碼來分析邏輯。
以上是C# 中的元數(shù)據(jù)的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

C# 隨機(jī)數(shù)產(chǎn)生器指南。在這裡,我們討論隨機(jī)數(shù)產(chǎn)生器的工作原理、偽隨機(jī)數(shù)和安全數(shù)的概念。

多線程和異步的區(qū)別在於,多線程同時(shí)執(zhí)行多個(gè)線程,而異步在不阻塞當(dāng)前線程的情況下執(zhí)行操作。多線程用於計(jì)算密集型任務(wù),而異步用於用戶交互操作。多線程的優(yōu)勢是提高計(jì)算性能,異步的優(yōu)勢是不阻塞 UI 線程。選擇多線程還是異步取決於任務(wù)性質(zhì):計(jì)算密集型任務(wù)使用多線程,與外部資源交互且需要保持 UI 響應(yīng)的任務(wù)使用異步。

C# 質(zhì)數(shù)指南。這裡我們討論c#中素?cái)?shù)的介紹和範(fàn)例以及程式碼實(shí)作。

C#和C 的歷史與演變各有特色,未來前景也不同。 1.C 由BjarneStroustrup在1983年發(fā)明,旨在將面向?qū)ο缶幊桃隒語言,其演變歷程包括多次標(biāo)準(zhǔn)化,如C 11引入auto關(guān)鍵字和lambda表達(dá)式,C 20引入概念和協(xié)程,未來將專注於性能和系統(tǒng)級編程。 2.C#由微軟在2000年發(fā)布,結(jié)合C 和Java的優(yōu)點(diǎn),其演變注重簡潔性和生產(chǎn)力,如C#2.0引入泛型,C#5.0引入異步編程,未來將專注於開發(fā)者的生產(chǎn)力和雲(yún)計(jì)算。

可以採用多種方法修改 XML 格式:使用文本編輯器(如 Notepad )進(jìn)行手工編輯;使用在線或桌面 XML 格式化工具(如 XMLbeautifier)進(jìn)行自動(dòng)格式化;使用 XML 轉(zhuǎn)換工具(如 XSLT)定義轉(zhuǎn)換規(guī)則;或者使用編程語言(如 Python)進(jìn)行解析和操作。修改時(shí)需謹(jǐn)慎,並備份原始文件。
