小编Omn*_*Owl的帖子

是否可以进行静态部分类?

我想拿一个课,把它分成几个小班,这样就更容易维护和阅读.但是我试图拆分的这个类partial是一个静态类.

我在Stackoverflow的一个例子中看到这是可能的,但是当我这样做时,它一直告诉我,我不能从静态类派生,因为静态类必须从对象派生.

所以我有这个设置:

public static class Facade
{
    // A few general methods that other partial facades will use
}

public static partial class MachineFacade : Facade
{
    // Methods that are specifically for Machine Queries in our Database
}
Run Code Online (Sandbox Code Playgroud)

有什么指针吗?我希望这个Facade类是静态的,这样我就不必在使用之前初始化它.

c# partial-classes

33
推荐指数
4
解决办法
1万
查看次数

矢量不是模板?

我目前正在尝试按照教程为自上而下的RPG制作一个简单的2D磁贴引擎.出于某种原因,虽然我得到了智能感知错误

vector is not a template

"向量"一词用红色加下划线.为什么这不起作用?为什么它告诉我它是一个模板,为什么程序不起作用?

#ifndef _IMAGEMANAGER_H
#define _IMAGEMANAGER_H

#include <vector>
#include <SFML\Graphics.hpp>

class ImageManager
{
private:
    vector<sf::Texture> textureList;

public:
    ImageManager();
    ~ImageManager();

    void AddTexture(sf::Texture& texture);
    sf::Texture& GetTexture(int index);
};
#endif
Run Code Online (Sandbox Code Playgroud)

我得到的错误(毫无疑问,其中一些错误来自上面这部分的错误):

  • 错误1错误C2143:语法错误:缺少';' 在'<'c:\ users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • 错误2错误C4430:缺少类型说明符 - 假定为int.注意:C++不支持default-int c:\ users\vipar\dropbox\computer
    science\programming\visual studio
    2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • 错误3错误C2238:';'之前的意外令牌 c:\ users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • 错误4错误C2143:语法错误:缺少';' 在'<'c:\ users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • 错误5错误C4430:缺少类型说明符 - 假定为int.注意:C++不支持default-int c:\ users\vipar\dropbox\computer
    science\programming\visual studio
    2012\projects\sfml-app\sfml-app\imagemanager.h 10 …

c++ vector sfml

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

无法在参考列表中找到Microsoft.Office.Interop.Word

由于我不知道如何将MS Word与C#集成,因此我得到了解决我遇到的问题的解决方案:http://www.dotnetperls.com/word

我查看了这个解决方案,我找不到Microsoft.Office.Interop.Word参考列表.我也无法在COM Objects下找到它.我错过了什么?我正在使用Visual Studio Express 2012.

编辑:

这个问题的答案是你必须在你的计算机上安装MS Office.

c# ms-word ms-office visual-studio-express visual-studio-2012

20
推荐指数
4
解决办法
5万
查看次数

将字符串转换为数学表达式?

让我们说我有一个方法声明这样:

public double Calc(String expression) {

// Code

}
Run Code Online (Sandbox Code Playgroud)

我想采用像String这样的String表达式

"2 + 4 - (3 * 4)"
Run Code Online (Sandbox Code Playgroud)

然后将其提供给它Calc(),它应该返回它获得的值.

你能从字符串中解析数学表达式,以便它成为Java可以理解的表达式吗?因为通常你可以写

return 2 + 4 - (3 * 4);
Run Code Online (Sandbox Code Playgroud)

但这只适用于那个单一的表达.

java math parsing

9
推荐指数
1
解决办法
3万
查看次数

BufferedInputStream将byte []通过Socket发送到数据库

我一直在寻找答案,但实际上找不到任何东西.今天早些时候,我问我如何通过字节数组将文件转换为字符串,然后再返回,以便稍后检索.

人们告诉我的是,我必须只存储字节数组,以避免令人讨厌的编码问题.所以现在我已经开始研究了这个问题,但现在我已经碰壁了.

基本上,我之前使用过无缓冲的流,将文件转换为字节数组.这在理论上很好用,但它会占用大量内存,最终会导致堆大小异常.我应该使用缓冲流(或者我被告知),而我现在遇到的问题是从BufferedInputStream到byte [].我试图复制并使用本文档中的方法

http://docs.guava-libraries.googlecode.com/git/javadoc/index.html?com/google/common/io/package-summary.html

我为缓冲流交换无缓冲流的地方.唯一的问题是,我不能直接将缓冲输出流转换为字节数组,因为我可以使用无缓冲的流.

救命?:)

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public final class BufferedByteStream {

    private static final int BUF_SIZE = 1024000;

    public static long copy(BufferedInputStream from, BufferedOutputStream to) throws IOException { 
        byte[] buf = new byte[BUF_SIZE];
        long total = 0;
        while(true) {
            int r = from.read(buf);
            if(r == -1) {
                break;
            }
            to.write(buf, 0, r);
            total += r;
        }
        return total;
    }

    public static byte[] toByteArray(BufferedInputStream in) throws IOException {
        BufferedOutputStream out = new …
Run Code Online (Sandbox Code Playgroud)

java arrays io bufferedinputstream bufferedoutputstream

8
推荐指数
1
解决办法
3万
查看次数

你如何清除WPF RichTextBox?

每当我这样做richtextbox1.Clear()时说该方法不存在.它几乎是我得到的唯一解决方案,无论我走到哪里.

我试过寻找Text房产,我也试图透过Document房产看,但无济于事.

我错过了什么?需要清除该框,就像您可以通过textbox.Clear()呼叫一样.

c# wpf richtextbox

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

客户端网站始终返回Null Json String

我已经达到了一个目的,我可以在我的WCF Web服务上收到客户网站的回复(我在我工作的公司内部使用).但每当我得到回应时,它总是为空.

我四处寻找各种解决方案,似乎没有一个解决这个问题.我有以下内容:

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "/AddNewActivity")]
String AddNewActivity(String jsonObject);
Run Code Online (Sandbox Code Playgroud)

并实施:

public String AddNewActivity(String jsonObject)
{
    return JsonConvert.SerializeObject("Success");
}
Run Code Online (Sandbox Code Playgroud)

只是为了测试它是否有效.我在上面的函数中设置了一个断点来读取jsonObject字符串并查看它的外观.当我读它时,它是空的.始终为空.

这是JavaScript:

function OnModalCreateNewActivityBtnClick() {
    var modal = $('#new-activity-modal-body');
    var activityMap = {
        status: modal.find('#new-activity-modal-status-dropdown').val(),
        name: modal.find('#new-activity-modal-name-field').val(),
        responsible: modal.find('#new-activity-modal-responsible-field').val(),
        department: modal.find('#new-activity-modal-department-dropdown').val(),
        startTime: modal.find('#new-activity-modal-datepicker-start').val(),
        endTime: modal.find('#new-activity-modal-datepicker-end').val(),
        description: modal.find('#editor').cleanHtml(),
        axAccounts: modal.find('#new-activity-modal-ax-account-numbers-field').val()
    };
    var jsonObject = '{ "String": ' + JSON.stringify(activityMap) + '}';
    $.ajax({
        type: 'POST',
        url: 'http://localhost:52535/PUendeligService.svc/AddNewActivity',
        data: jsonObject,
        contentType: 'application/json; …
Run Code Online (Sandbox Code Playgroud)

javascript c# wcf json

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

JavaScript函数运行两次?

我有点困惑.

我有一个用户可以单击的复选框,用于确定我的页面上的私人电话号码是对所有人还是仅对管理员可见.当单击该框时,我想确保您首先被允许首先打印它的状态仅用于测试目的.当我运行此功能时,它会运行两次.

我在其他地方读到这是因为Callbacks?但是我回复假,所以这不应该是这样的吗?

我不是一个JavaScript向导,所以我仍然不了解JavaScript及其与ASP的交互.

/**
* Used to Check whether a Private Phone number should be hidden or shown.
*/
function ValidateHidePrivate() {
    if (scope["pickeduser"] != scope["credential"]) {
        alert("Not allowed");
        return false;
    } else {
        alert(document.getElementById("HidePrivate").checked);
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

和HTML:

<label for="HidePrivate" onclick="ValidateHidePrivate()">
    <input type="checkbox" name="HidePrivate" id="HidePrivate" value="no" />
    Hide my Private Phone Number
</label>
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

html javascript asp.net-mvc events function

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

如何绕过FormSpree重定向?

我在Github Pages服务上获得了我的网站.我正在尝试实施FormSpree免费联系表单,但在您提交表单后,它会将您重定向到其他网站.我想避免的东西.所以我在互联网上查了一下,当然其他人也希望摆脱它(我在下图中省略了我的电子邮件).

在此输入图像描述

这是我上面提到的形式,但它实际上根本不起作用.它在我试图摆弄它之前起作用了.

以下是FormSpree默认情况下的表单:

<form action="//formspree.io/your@email.com"
      method="POST">
    <input type="text" name="name">
    <input type="email" name="_replyto">
    <input type="submit" value="Send">
</form>
Run Code Online (Sandbox Code Playgroud)

这是我的版本(在我尝试绕过重定向之前工作正常)

<div class=modal-body style="background-color: #454545">
    <p>Please use the form below to contact us regarding feedback or any questions you may have!
        We will never use the information given below to spam you and we will never pass on your
        information to a 3rd party.</p>
    <p>As we are using <a target="_blank" href="http://formspree.io">FormSpree</a> for this form
    please consult their privacy policy for any questions regarding …
Run Code Online (Sandbox Code Playgroud)

html javascript forms

7
推荐指数
3
解决办法
1万
查看次数

Visual Studio调试立即停止在MVC中上传文件吗?

因此,我试图使用Visual Studio 2019 Enterprise进入.NET Core MVC。

我尝试从Microsoft自己的文档中遵循一个非常简单的示例。设置代码后,我得到了模板项目,它们为您提供了MVC。因此,在“关于”页面上,我具有以下控制器类AboutController.cs以及在Microsoft网站上找到的方法:

[HttpPost("UploadFiles")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
    long size = files.Sum(f => f.Length);
    string filePath = Path.GetTempFileName();

    if (files.Count > 0)
    {
        IFormFile file = files[0];
        if (file.Length > 0)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
        }
    }

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

唯一的“大”区别是我返回视图,而不是“确定”,因为我对此并不真正感兴趣。我想修改我正在查看的视图,而不是使用全新的视图(也许我误解了MVC的工作原理?)。

现在我的HTML看起来像这样:

[HttpPost("UploadFiles")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
    long size = files.Sum(f => f.Length);
    string filePath = Path.GetTempFileName();

    if (files.Count > …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-core

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