小编Chr*_*ris的帖子

如何将表单添加到控制台应用程序以便用户可以选择文件?

我创建了一个控制台应用程序,让它以我想要的方式工作.使用VS2010中的"添加项目">"添加Windows窗体"选项,它自动创建了我需要的内容.我添加了一个按钮和代码来检索Excel文件(如下所示)我的问题是:

如何获取他们创建的文件并在program.cs"Main"区域中使用它?

来自Form1.cs的OpenFileDialog按钮单击事件的代码:

private void btnSelect_Click(object sender, EventArgs e)
{
OFD.openFileDialog OFD = new OpenFileDialog();
OFD.Multiselect = false;
OFD.Title = "Open Excel Document";
OFD.Filter = "Excel Document|*.xlsx;*.xls";
OFD.ShowDialog();
string docPath = OFD.FileName;
}
Run Code Online (Sandbox Code Playgroud)

我的静态主事件的那部分我希望从program.cs文件中创建"docPath"

static void Main(string[] args)
    {
        var excel = new ExcelQueryFactory();
        excel.FileName = @"C:\Users\Christopher\Desktop\BookData\TestResults.xls";
       <...code executed on opened excel file...>
     }
Run Code Online (Sandbox Code Playgroud)

感谢您的时间.

这是我完成的解决方案:

class Program
{
    [STAThread]
    static void Main(string[] args)
    {

        var excel = new ExcelQueryFactory();
        OpenFileDialog OFD = new OpenFileDialog();
        OFD.Multiselect = false;
        OFD.Title = …
Run Code Online (Sandbox Code Playgroud)

c# openfiledialog console-application winforms

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

XCCDF 上的 C# Linq-to-XML

我正在尝试从 XCCDF 输出文件中解析出信息,但我的 Linq-to-Xml 查询一直返回空值。以下是我迄今为止尝试过的一些方法:

XElement xelement = XElement.Load(s);
IEnumerable<XElement> findings = xelement.Elements();
XNamespace ns = "http://checklists.nist.gov/xccdf/1.1";

var findingDetails = from f in findings.Descendants(ns + "Benchmark")
                     select new
                     {
                         title = f.Element("title").Value            
                     };

foreach (var fd in findingDetails)
{
    Console.WriteLine(fd.ToString());
}
Run Code Online (Sandbox Code Playgroud)

我也试过:

var findingDetails = from f in findings.Descendants(ns + "Benchmark")
                     select f;

var findingDetails = from f in findings.Descendants("Benchmark")
                     select new
                     {
                         title = f.Element("title").Value             
                     };

var findingDetails = from f in findings.Elements(ns + "Benchmark")
                     select new
                     {
                         title …
Run Code Online (Sandbox Code Playgroud)

c# xml linq linq-to-xml

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

Python 3.5 ctypes libc printf() 只打印字符串 Windows 7/10 的第一个字节

我正在尝试遵循 Gray Hat Python 示例之一,它在 Python 2.7 中运行良好,但在 Python 3.5 中结果被截断。

from ctypes import * 

msvcrt = cdll.msvcrt
message_string = "Hello World!\n"
msvcrt.printf("Testing: %s\n", message_string)
Run Code Online (Sandbox Code Playgroud)

您可以看到上面代码的输出下面只是字母T

在此处输入图片说明

基于与此类似的其他一些帖子,b在最后一行添加 a 有帮助,但随后message_string被截断。

from ctypes import * 

msvcrt = cdll.msvcrt
message_string = "Hello World!\n"
msvcrt.printf(b"Testing: %s\n", message_string)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如何message_string在 Windows 7 或 10 上使用 Python 3.5打印存储在变量中的整个字符串?

c python windows pydev

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

如何使用每种类型的循环迭代通用列表

我已经获得了一个创建列表的列表,我可以使用'for each'类型的'for'循环遍历列表,而不是为Iterator构建一个构造函数.问题是当我下面的代码时,我得到错误消息"只能迭代数组或java.lang.Iterable的实例".这是代码:

public static void main(String[] args) {
    GList<InnerList> list = new GList<InnerList>(); 
    GList<InnerList> numList = new GList<InnerList>();
    InnerList lst = new InnerList ();
    Scanner sc = new Scanner(System.in);
    String answer;      
    while (true){
        System.out.println ("Do you want to create a list (y/n)? ");
        answer = sc.next();
        if (answer.equals("y")){
            System.out.println("Enter the name of the list: ");
            answer = sc.next();
            lst.setName(answer);
            if (list.isEmpty()== true){
                list.insertFirstItem(lst);
            }
            else {
                list.insertNext(lst);
            }           
        }               
        while (true){
            System.out.println("Do you want to enter a number (y/n)?");
            answer …
Run Code Online (Sandbox Code Playgroud)

java collections foreach generic-list

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

PowerShell Foreach循环在多次成功尝试后未执行

我创建了以下PowerShell函数来遍历用户指定目录中的文件,将DISA FSO提供的CCI值与目录中每个STIG的测试ID相结合,并将该数据输出到.csv文件中.用户选择.

代码工作PowerShell ISE,然后我尝试了它PowerShell Terminal,它不再适用于任何一个.

当我执行时function,它会询问并存储参数,但主循环不会执行(在第23行的注释中).在调试时,我看到foreach完全跳过了循环.要使foreach循环执行,我需要做什么?

我试过的事情:

  • 将param移到函数外面
  • 在函数声明之前或之后调用函数(即,在脚本的顶部或底部
  • 删除检查if用户指定的输出文件存在
  • 在输出文件存在后添加变量检查以显示参数(显示 - 跳过后的任何内容)

当前功能状态:

Function CreateTestPlan {
    param (
        [Parameter(Mandatory = $true, HelpMessage="Filename of DISA STIG Benchmark XCCDF.xml file. Downloaded from IASE website. Usage: -BenchMarksDir")]
        [string]$BenchMarksDir,
        [Parameter(Mandatory = $true, HelpMessage="Filename of DISA CCI .XML file. Downloaded from IASE website. Usages: -CCIFile")]
        [string]$CCIFile,
        [Parameter(Mandatory = $true, HelpMessage="Filename of your choosing, ending in .csv. Usages: -OutFile")]
        [string]$OutFile,
        [Parameter(Mandatory = $true, …
Run Code Online (Sandbox Code Playgroud)

xml powershell foreach

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

通用列表中的NullPointerException

我一直在搜索stackoverflow上的1000个NullPointerException帖子,并且在我的生活中不能说明为什么会发生这种情况; 除了明显的(它是空的).有人可以帮助我理解我不理解Generic Singly LinkedList导致我得到这个运行时错误的内容.

这是我的代码:

    import java.io.*;
    import java.util.*;

public class GList<T> {         
    private GNode<T> head;
    private GNode<T> cursor;

    private static class GNode<E>{
    private E data;        //NULLPOINTEREXCEPTION
    private GNode<E> next;

    public GNode(E data, GNode<E> next) {
        this.data = data;
        this.next = next;
    }
}                
public static class InnerList<E> {
    private String name;
    private GList<Integer> inner = new GList<Integer>();

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public GList<Integer> getInner() {
        return inner; …
Run Code Online (Sandbox Code Playgroud)

java generic-list nullpointerexception

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

GetEnumerator在此上下文中不存在

我已经实现了一个自定义链表,我在实现IEnumerator <>时遇到了问题.具体来说,编译器告诉我The name "GetEnumerator" does not exist in the current context.我觉得我正在实现它,正如我在众多stackoverflow帖子和教程中看到的那样,我错过了什么?

这是我的数据结构:

namespace TestReportCreator_v3
{
    public class FindingsTable : IEnumerable<string>
    {
        private Node head, mark;
        public class Node
        {
            public string description; //covers weakness, retinaDesc, nessusDesc
            public string riskLevel; //covers impactLevel, retinaRisk, nessusRisk
            public string boxName; //box name results apply to
            public string scanner; //wassp, secscn, retina, nessus
            public string controlNumber; //ia control number impacted, wassp and secscn only
            public string fixAction; //comments, retinaFix, nessusSolu
            public string auditID; …
Run Code Online (Sandbox Code Playgroud)

c# ienumerable ienumerator linked-list

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