operation - 获取设置操作无法正常工作?
问题描述
我已经尝试了几个小时来修复此代码,但我似乎无法理解问题所在,我将一个带有 get 和 set 的变量存储在一个包含 switch case 的公共内部。我要做的是使用下面的这个菜单来存储变量,然后在下面打印出来,但是一旦我跳出开关盒,它就不再存储新变量而是旧变量。
{
Volume vol = new Volume();
Console.WriteLine("\n ---------------\n" +
" |>>>>> Control Panel <<<<<|\n" +
" ---------------" +
"\n\n |===========================================|\n" +
"\n Press key...\n" +
"\n [Q] to Change M Main 1 Volume\n" +
" [W] to Change M Main 2 Volume\n" +
" [E] to Change Host Volume\n" +
" [R] to Change Guest Volume\n" +
" [T] to Change Speaker Volume\n" +
" [Y] to Change Lights\n" +
" [G] to exit\n" +
"\n |===========================================|");
ConsoleKeyInfo inputuser = Console.ReadKey(true);
switch (inputuser.Key)
{
case ConsoleKey.Q:
{
try
{
Console.WriteLine("| | |Input Volume percentege from 0-100 %| | |");
vol.MainMic1 = int.Parse(Console.ReadLine());
if (vol.MainMic1 > 100 || vol.MainMic1 < 0)
{
Console.WriteLine("Invalid Number");
Console.ReadKey();
}
else if (vol.MainMic1 == 0 || vol.MainMic1 <= 100)
Console.WriteLine(vol.MainMic1);
Console.ReadKey(); ```
这将它设置在当前方法中,因为我尝试了它,但不是在我用来调用它的方法中,当我在控制台中调用它时,它返回其原始值或 0
public void ShowVolume()
{
Volume voll = new Volume();
Console.Clear();
Console.WriteLine("|====== ====== ====== ====== ====== ====== ======|\n" +
"\n >>>>> Lights and Volume settings <<<<<\n" +
"\nMain 1(Peterson) Microphone currently at: {0}% volume.\n" +
"Co-Speaker(Weiss) Microphone currently at: {1}% volume.\n" +
"Host Microphone currently at: {2}% volume.\n" +
"Guest Microphone currently at: {3}% volume.\n" +
"Quad-Speakers currently at: {4}% volume.\n" +
"Lights are at: {5}% power.\n" +
"\n|====== ====== ====== ====== ====== ====== ======|", voll.MainMic1, voll.MainMic2, voll.MainMic3, voll.GuestMic, voll.QuadSpeaker, voll.Lighting);
Console.ReadKey();
我无法弄清楚问题所在,我可以运行所有内容,但不能打印所要求的内容,我不明白这里是否存在某种案例/方法阻塞?
here is class with get/set
public class Volume
{
private int o_mainmic1 = 50;
private int o_mainmic2 = 50;
private int o_mainmic3 = 50;
private int o_guestmic = 30;
private int o_quadspeaker = 30;
private int o_lighting = 30;
public int MainMic1
{
get
{
return o_mainmic1;
}
set
{
o_mainmic1 = value;
}
}
如果对您有帮助,这里有一些 Gyazo 图片,我很感谢我在这里得到的任何帮助,在此先感谢。
https://gyazo.com/d241e1f8db821ba38415ecf1c57fb3f9
https://gyazo.com/35f31140568794aa41ee74c8ead2296a
https://gyazo.com/1359b4a291baa385b8dcee586a3b97ea
https: //gyazo.com/ 1ce9e237fdd56a7f1a40dabd24c50b5a```
解决方案
推荐阅读
- android - 在 Jetpack Compose UI 中设置内容视图的方法
- python - 如何用另一个字典列表过滤字典列表
- python - 是否有将根据训练数据计算的 WOE 添加到整个数据集的功能?(Python)
- azure - 如何在 Azure Web App 中为容器装载 docker 卷?
- google-bigquery - BigQuery ML K-means 与训练模型后的新数据集
- java - 为什么我收到 javax.mail.AuthenticationFailedException?
- apache-storm - 连接数据库的风暴螺栓
- java - Spring Security 5 无法添加自定义 AccessDecisionManager
- angular - 如何再次将js映射到ts
- python - 以预定间隔从摄像机视频中提取图像