标签: void

在C#上使用全局变量

所以我必须使用它 void

static void PerformOption(int option)
Run Code Online (Sandbox Code Playgroud)

但是我希望这个int选项能够被其他人使用void.我知道这可以通过删除括号内部并指定一个static int但我必须使用int选项来完成void,所以我不能改变这个.

那么如何将选项作为全局变量呢?

c# variables static global void

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

在交换函数中使用void指针

我有一个像这样的交换函数:

void swap(int i, int j, void* arr[])
{
    void *temp;
    temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
}
Run Code Online (Sandbox Code Playgroud)

我在主要调用swap这样:

main()
{
    int arr[8] = {4,7,9,2,6,7,8,1};
    void *ptr = arr;
    swap(0, 1, ptr);
    int k;
    for (k=0; k<8; k++)
        printf("%d ", arr[k]);
}
Run Code Online (Sandbox Code Playgroud)

现在,交换似乎工作正常,但不是将1值与另一个值交换,而是将另外2个值交换为2个值.例如,当我交换(0,1,ptr)时,我得到了数组

9,2,4,7,6,7,8,1
Run Code Online (Sandbox Code Playgroud)

当我应该得到:

7,4,9,2,6,7,8,1
Run Code Online (Sandbox Code Playgroud)

它不是交换4和7,而是用9,2交换4,7.它为什么这样做?

c swap pointers void

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

这里不允许'void'类型(java)错误

这是我的代码:

public void start()
{
  //If the gas tank and oil have more than nothing, and the transmission is in gear park, then the car can start
  if((gasTank.getGasLevel() > 0) && (engine.getOilLevel() > 0) && (transmission.gearPark()))
  {
    engine.startEngine();
    System.out.println("Engine is now on");
  }
  else
  {
    System.out.println("Please make sure your car is in proper gear, engine has oil and gas.");
  }
}
Run Code Online (Sandbox Code Playgroud)

我一直在收到'void' type not allowed here错误.我不是想要返回任何东西所以我知道我不需要int,Boolean,double等.

我究竟做错了什么?

java types void

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

如何在java中打印void

以下语句返回void

Pattern lazy = Pattern.compile("X??");
Matcher lazyMatcher = lazy.matcher("X");
if (lazyMatcher.matches()) {
  System.out.println(lazyMatcher.group());
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在java中打印void.

我尝试了以下两个陈述,但没有帮助

System.out.println((String)lazyMatcher.group());
System.out.println(lazyMatcher.group().toString());
Run Code Online (Sandbox Code Playgroud)

================================================== ===========================正在更新

当我在下面打电话时,为什么我会收到String

System.out.println(lazyMatcher.group().getClass())  // returns string
System.out.println(lazyMatcher.group()) // returns void
Run Code Online (Sandbox Code Playgroud)

java void

0
推荐指数
2
解决办法
9919
查看次数

从Java类中调用方法

基本上,我在做赌博游戏。它询问该人要下多少赌注,然后,如果他们是正确的话,那么他们的“钱包”就会增加,无论他们赢得多少,这取决于给定的赔率。我正在为个人“钱包”专门开设一门课程。

public class Wallet {

    private double cash;

    public Wallet() {cash=0.0;}

    public void put(double money) {
        assert money > 0 : "Die : pre-condition violated ! ";

        cash=cash+money;
    }

    public boolean get(double money) {
        if (money>0 && cash>=money) {
            cash=cash-money;
            return true;
        }
        return false;
    }

    public double count() {return cash;}

    public String toString(){
        return getClass().getName()+ "[cash = ]" + cash + "]";
    }
Run Code Online (Sandbox Code Playgroud)

我在put()此类之外调用该方法有麻烦。应该如何编写我的代码行才能被调用?我应该使用变量名money来存储双精度数,或者完全不同的变量名。

java public void

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

cpp(15):错误C2182:'input':非法使用'void'类型

在重新开始我用于学习阵列如何与void组合工作的新程序之后我遇到了以下问题.

cpp(15): error C2182: 'input' : illegal use of type 'void'
Run Code Online (Sandbox Code Playgroud)

有谁知道是什么原因造成的?我是虚空和数组概念的新手.

#include "stdafx.h"
#include <iostream>
using namespace std;
void input (int x );

int main()
{
    int x = 0;
    int a[ 5 ];
    input ( a[ 5 ]);
    {
        void input(x);
        for(int i = 1; i < 5; i++) {
            cin >> a [ i ];
        }
        cin.get();
        cout << a [ 3 ];
        cin.get();
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ void

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

制造虚空动态

我创建了一些动态的图片框,但我不知道如何对点击进行单独操作.

PictureBox[] app=new PictureBox[file.Length];
int i = 0, prev=20;
foreach(string element in file)
{
    app[i] = new PictureBox();
    app[i].BackgroundImage = Image.FromFile(element.Remove(element.Length - 3) + "png");
    app[i].Location = new Point(prev, 85);
    app[i].Size = new Size(100, 100);
    app[i].Name = "test" + i;
    app[i].Click += new EventHandler(run(element, dir));

    this.Controls.Add(app[i]);

    i++; 
    prev += 20;
}

private void run(string element, string dir)
{
      MessageBox.Show(element);
}
Run Code Online (Sandbox Code Playgroud)

那我怎么能这样做呢.请帮忙!谢谢!

c# events dynamic void winforms

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

为什么我会收到此错误?线程"main"中的异常java.lang.NoClassDefFoundError:"

这是完整的错误消息:

Exception in thread "main" java.lang.NoClassDefFoundError: DataEntry/java
Caused by: java.lang.ClassNotFoundException: DataEntry.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

    import java.awt.*;
    import java.awt.event.*;

    public class DataEntry {
      public static void main(String[] args) {
      Frame frm=new Frame("DataEntry frame");
      Label lbl = new Label("Please fill this blank:");
      frm.add(lbl);
      frm.setSize(350,200);
      frm.setVisible(true);
      frm.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
      System.exit(0);
      }
      });
      Panel p = new Panel();
      Panel p1 = new Panel();
      Label jFirstName = new Label("First Name");
      TextField …
Run Code Online (Sandbox Code Playgroud)

java static program-entry-point args void

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

在PHP中返回void和null之间有区别吗?

当我有这样的功能:

public function getResult() {
    return;
}
Run Code Online (Sandbox Code Playgroud)

它与返回null完全相同吗?如果我这样做:

is_null($this->getResult());
Run Code Online (Sandbox Code Playgroud)

这会导致真的吗?

php null void

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

c#扩展方法 - 添加一个void方法

扩展方法当然有用于将方法添加到您不拥有的类.

但我想在Visual Studio中练习这个概念,但不确定所需的符号.

例如,我有以下课程

public static class Dog
{
    public static void Bark()
    {
        Console.WriteLine("Woof!");
    }
}
Run Code Online (Sandbox Code Playgroud)

让我们假设我不拥有这种方法(我这样做,但让我假装不这样做).我如何使用名为Jump的新方法(在本质上为void)扩展类,其中所有新方法都将打印到Dog跳跃的控制台?

我试图使用以下方法添加:

public static class SomeOtherClass
{
    //extension method to the Dog class
    public static Dog Jump(this Dog)
    {
        Console.WriteLine("Dog Jumped");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

"狗:静态类型不能用作参数"

"狗:静态类型不能用作返回类型"

你能帮我解决一下这个问题吗?

c# extension-methods static-methods void

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