我在哪里弄错了?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我在哪里弄错了?相关的知识,希望对你有一定的参考价值。
我在同一解决方案的3层体系结构中有3个项目。
但是我无法在演示文稿层中显示我的演示文稿我收到错误CS0103,我的想法是该层无法访问其引用的层中使用的方法。如果是这种情况,那么我该如何引用这些方法或建议一种简便的方法呢?
我的表示层引用了以下代码
using Data_Link;
using static Data_Link.Program;
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Business_Logic
{
public class Program
{
List<Card> CrackableCards = GetCrackablePINS(AllCards);
List<Card> ExpiredCards = GetExpiredCards(AllCards);
List<Card> ExpiringCards = GetExpiringCards(AllCards);
List<Card> HNWIs = GetHNWI(AllCards);
public static List<Card> AllCards { get; private set; }
/* List<Card> AllCards = new List<Card>();
public int[] computeFrequency(List<LotteryEntry> historicalData)
public static
*/
//Returns crackable pins
private static List<Card> GetCrackablePINS(List<Card> cards)
{
List<Card> CrackableCards = GetCrackablePINS(AllCards);
List<Card> results = new List<Card>();
foreach (var card in cards)
{
if (IsCrackable(card.CardPIN))
results.Add(card);
}
return results;
}
//Returns expired cards
private static List<Card> GetExpiredCards(List<Card> cards)
{
List<Card> results = new List<Card>();
foreach (var card in cards)
{
if (HasExpired(card.ExpiryDate))
results.Add(card);
}
return results;
}
//Returns expiring cards
private static List<Card> GetExpiringCards(List<Card> cards)
{
List<Card> results = new List<Card>();
foreach (var card in cards)
{
if (IsExpiring(card.ExpiryDate))
results.Add(card);
}
return results;
}
//Returns HNWIs
private static List<Card> GetHNWI(List<Card> cards)
{
List<Card> results = new List<Card>();
foreach (var card in cards)
{
if (IsHNWI(card.CardLimit))
results.Add(card);
}
return results;
}
//Generates report in csv
private void GenerateReport(List<Card> cardCriteria, string fileName)
{
string heading = "Card Type Code,Card Type Full Name,Issuing Bank,Card Number,Card Holder's Name,CVV/CVV2,Issue Date,Expiry Date,Billing Date,Card PIN,Credit Limit";
File.WriteAllText(fileName, heading);
foreach (var card in cardCriteria)
{
try
{
string details = card.CardTypeCode + "," + card.CardTypeFullName + "," + card.IssusingBank + "," + card.CardNumber + "," + card.CardHolderName + "," + card.CVV + "," + card.IssueDate + "," + card.ExpiryDate + "," + card.BillingDate + "," + card.CardPIN + "," + card.CardLimit;
File.AppendAllText(fileName, details);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
//Checks if a card pin is crackable
private static bool IsCrackable(string PIN)
{
if (PIN[0] == PIN[1] || PIN[1] == PIN[2] || PIN[2] == PIN[3])
{
return true;
}
else if ((int)PIN[0] == (int)PIN[1] - 1 && (int)PIN[1] == (int)PIN[2] - 1 && (int)PIN[2] == PIN[3] - 1)
{
return true;
}
else
{
return false;
}
}
//Checks if the card has expired
private static bool HasExpired(string date)
{
string[] dateString = date.Split('/');
int month = int.Parse(dateString[0]);
int year = int.Parse(dateString[1]);
if (month <= 2 && year <= 2020)
return true;
else
return false;
}
//Checks if the card is expiring
private static bool IsExpiring(string date)
{
string[] dateString = date.Split('/');
int month = int.Parse(dateString[0]);
int year = int.Parse(dateString[1]);
if (month == DateTime.Now.Month && year == DateTime.Now.Year)
{
return true;
}
else
{
return false;
}
}
//Checks if a card is an HNWI
private static bool IsHNWI(int HNWI)
{
const int limit = 149999;
if (HNWI > limit)
return true;
else
return false;
}
}
}
答案
您正在使用静态BusinessLogic.Program
,将允许访问public static
的BusinessLogic.Program
成员。
但是,您的字段(ExpiredCards
等)是非静态的,并且是private
(默认情况下)。在每一项之前都添加public static
。
也就是说,避免静态数据可能更易于维护。而是在BusinessLogic.Program
中创建和创建Main()
的实例。
以上是关于我在哪里弄错了?的主要内容,如果未能解决你的问题,请参考以下文章
我在哪里更改此 Python 代码片段以将临时文件保存在 tmp 文件夹中?