簡體   English   中英

如何添加程序集引用以在 c# 中使用 Rect?

[英]How do I add the assembly reference to use Rect in c#?

我想使用Rect結構,我寫Rect aaa = new Rect(); 我得到the type or namespace could not be found錯誤。 我嘗試添加所有using s,如網絡示例中所示:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

我發現最后三個導入了the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?) the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?)

在提到的網頁上,它說程序集是WindowsBase.dll 現在我不知道如何繼續......

更新:我被告知要添加一個參考,但它是一個核心項目, 這是不可能的

我應該安裝一個包,但我沒有看到任何包含這個 dll 的 WindowsBase 包對 .net 5 無效,但在上面的文檔中它說這個 Struc 確實可以與 .net 5 一起使用。

我想使用這個結構。

簡短回答:正如@imsmn 所評論的,添加對 WindowsBase 的引用。 通過右鍵單擊解決方案資源管理器中的“引用”條目並選擇“添加引用”來執行此操作。

長答案(或更准確地說,建議):

將來獲得答案的簡單方法:對於沒有歧義的“內置”類,您可以嘗試這個。 在 Visual Studio 中,在代碼窗口(C# 編輯器)中鍵入:

Rect r = new Rect();

然后將鼠標懸停在出現在“Rect”一詞下方的紅色波浪線上。 將彈出一個框,其中一個選項是“顯示潛在修復”。 如果單擊它,選項之一通常是添加引用(如果需要)和 using 指令(如果需要)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM