小编Sup*_*cko的帖子

变量在当前上下文中不存在?

我知道这很可能是一个愚蠢的问题,但我是一名大学生,他是C#和面向对象编程的新手.我试图在别处找到答案,但我找不到任何有用的东西.调试器一直告诉我变量'cust_num在当前上下文中不存在'.如果有人能告诉我我做错了什么并让我觉得自己像个白痴,我会非常感激.谢谢!

    string get_cust_num()
    {
        bool cust_num_valid = false;

        while (!cust_num_valid)
        {
            cust_num_valid = true;
            Console.Write("Please enter customer number: ");
            string cust_num = Console.ReadLine();

            if (cust_num == "000000" || !Regex.IsMatch(cust_num, @"^[0-9]+$") || cust_num.Length != 6)
            {
                cust_num_valid = false;
                Console.WriteLine("Invalid customer number detected. Customer numbers must be a 6 digit positive integer (zeros will not work)");
            }
        }

        return cust_num;
    }
Run Code Online (Sandbox Code Playgroud)

c# scope return

6
推荐指数
2
解决办法
4万
查看次数

为什么在没有做任何事情之间存在合理的内容空间?

我正试图通过使用使得top-navbot-nav分区垂直分开justify-content: space-between.但是,它没有做任何事情.有人能指出我做错了吗?

@import url(https://fonts.googleapis.com/css?family=Rock+Salt);
 html {
  font-family: 'Rock Salt', cursive;
}
.flex-container {
  display: flex;
}
header {
  width: 300px;
  height: 100vh;
  position: fixed;
  background-color: blue;
}
nav.flex-container {
  align-items: center;
  flex-direction: column;
  justify-content: space-between;
}
ul {
  padding: 0;
  margin: 0;
  list-style-type: none;
}
#logo-container {
  background-color: red;
  width: 100%;
}
#logo {
  margin: auto;
  padding: 10px 0;
}
Run Code Online (Sandbox Code Playgroud)
<body>
  <div id="root-container">
    <header>
      <div id="logo-container" class="flex-container">
        <h2 id="logo">Name Goes Here</h2>
      </div>
      <nav class="flex-container"> …
Run Code Online (Sandbox Code Playgroud)

html css html5 css3 flexbox

2
推荐指数
1
解决办法
5755
查看次数

继承文字字符串问题的构造方法

这可能是一个很容易解决的问题.我是一名大学生,我们刚刚开始使用多态,所以这个概念对我来说仍然令人费解.

abstract class IncreaseTransaction
{
    private string _Description;
    private decimal _Amount;        

    protected IncreaseTransaction(string description, decimal amount)
    {
        _Description = description;
        _Amount = amount;
    }
}

class Deposit : IncreaseTransaction
{
    public Deposit(string description, decimal amount) : base("Deposit", amount)
    {
    }
}

static void Main(string[] args)
{
    Customer fred = new Customer("Fred");
    SavingsAccount fredSavings = new SavingsAccount();
    fredSavings.AddTransaction(new Deposit(500.00M));
}
Run Code Online (Sandbox Code Playgroud)

当实例化新存款时,我希望将文字字符串"存款"用作交易的描述.但是,我收到一条错误,指出'SampleNamespace.Deposit不包含一个带有一个参数的构造函数'.所以,字符串没有被继承,我不确定如何解决这个问题.我非常感谢任何帮助!

c# inheritance constructor abstract-class

1
推荐指数
1
解决办法
45
查看次数

标签 统计

c# ×2

abstract-class ×1

constructor ×1

css ×1

css3 ×1

flexbox ×1

html ×1

html5 ×1

inheritance ×1

return ×1

scope ×1