簡體   English   中英

我在 C# 中收到錯誤“命名空間中不存在類型或命名空間名稱”

[英]I get an error in C# "The type or namespace name does not exist in namespace"

我在 C# 中收到錯誤“命名空間中不存在類型或命名空間名稱”。 我到處檢查但它沒有解決我的問題這里是主程序

using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
using BlockChainMySelf;
using Formatting = Newtonsoft.Json.Formatting;

namespace BlockChainMySelf
{
    class Program
    {
        static void Main(string[] args)
        {
            var startTime = DateTime.Now;

            BlockChainMySelf.BlockChain StepCoin = new BlockChain();
            StepCoin.CreateTransaction(new Transaction("Henry", "MaHesh", 10));
            StepCoin.CreateTransaction(new Transaction("lkjsdf", "MaADLKHesh", 15));
            StepCoin.CreateTransaction(new Transaction("Henry", "MaHesh", 20));
            StepCoin.CreateTransaction(new Transaction("Henry", "MaHesh", 60));
            StepCoin.ProcessPendingTransactions("Bill");

這是我想打電話的班級

using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
using BlockChainMySelf;
using Formatting = Newtonsoft.Json.Formatting;

namespace BlockChainMySelf
{
    public class BlockChain
    {
        IList<Transaction> PendingTransactions = new List<Transaction>();
        public IList<Block> Chain { set; get; }
        public int Difficulty { set; get; } = 2;

這是屏幕截圖主要

班級

回答問題

回答問題2

您問題的早期編輯中的第二個屏幕截圖清楚地將BlockChain類顯示為 Visual Studio 中的“雜項文件”:

第二個截圖

雜項文件項目MSDN 頁面說(強調我的):

當用戶打開項目項時,IDE 會將不是解決方案中任何項目成員的任何項分配給 Miscellaneous Files 項目。

大概您正在嘗試解決問題,因此您將static放入 - 但這不起作用,因為您無法創建BlockChain的實例。

您的問題是Visual Studio的副本- 項目顯示為 “Miscellaneous Files”

解決方案是右鍵單擊解決方案資源管理器中的錯誤文件,將其從項目中刪除,然后重新添加它,例如這個答案

我有這個問題......但是,我在同一個命名空間下有兩個類,但在不同的項目中。 我所要做的就是直接添加對項目的引用。

暫無
暫無

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

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