小编use*_*117的帖子

初学c#麻烦

我是c#的新手,我有一点问题.我想制作一个简单的程序来询问用户1-50之间的整数,然后在控制台上显示是否为奇数.所以,我试过的是这样的:

 Console.WriteLine("Skriv ut ett heltal: ");
 int x = int.Parse(Console.ReadLine());

 if (x == 1,3,5,7,9,11,13,15,17,19)
 {
     Console.WriteLine("The number is odd");
 }
 else 
 {
     Console.WriteLine("The number is not odd");
 }
Run Code Online (Sandbox Code Playgroud)

现在我在if语句中遇到错误.我怎样才能解决这个问题?

c#

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

C#变量,方法,参考练习

我在C#上做了一个练习,这里是:

class Program
{
    static double funk(int a, ref int b)
    {
        double c = a + b;
        a = 5;
        b = a * 3;
        return c;
    }

static void Main(string[] args)
{
    int a = 1, b = 2;
    Console.WriteLine(funk(a, ref b));
    Console.WriteLine(a);
    Console.WriteLine(b);
    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

因此,当我运行代码时结果非常清楚,它给了我:

3
1
15
Run Code Online (Sandbox Code Playgroud)

我现在的问题是,15和3来自哪里?

c#

-3
推荐指数
1
解决办法
217
查看次数

标签 统计

c# ×2