我很想知道哪一个更好用,因为我必须在c#的代码中再次检查它
if(args.Length<1) //i use
Run Code Online (Sandbox Code Playgroud)
VS
if(args.Length == 0 || args == null)
Run Code Online (Sandbox Code Playgroud)
作为替代.
或者如果有可能的话,也可以
if (args.exists) // or more simple?
Run Code Online (Sandbox Code Playgroud) 我在winforms应用程序中使用visual c#.我想查看是否*.plr存在,删除所有带扩展名的文件.plr.我很困惑,因为以下代码由于某种原因不起作用.
if (File.Exists("*.plr"))
{
File.Delete("*.plr");
}
Run Code Online (Sandbox Code Playgroud) 以下代码检查类A中是否存在foo()方法.此代码在vs2013下编译,但静态断言在vs2015上失败.哪个编译器版本说实话?如果vs2015,那么如何修复代码?
#include <type_traits>
struct MethodTester_foo {
template<typename U, typename MethodType>
static auto test(U* p) -> decltype(static_cast<MethodType>(U::foo));
template<typename U, typename MethodType> static auto test(...)->std::false_type;
};
template <typename Class, typename MethodType, class MethodTester>
using HasMethod =
typename std::conditional
<
std::is_same<
decltype(MethodTester::template test<Class, MethodType>(0)),
std::false_type
>::value,
std::false_type, std::true_type
>::type;
struct A { int foo() { return 1; } };
static_assert(HasMethod<A, int(A::*)(), MethodTester_foo>::value, "Has no method named foo");
Run Code Online (Sandbox Code Playgroud) 编辑:注意:我正在使用Visual Studio 2015
我正在尝试使用VSIX项目编写一个VisualStudio扩展,它显示当前加载的解决方案的所有引用.
我可以使用下面的代码获取当前的解决方案和项目(所有项目,实际上).
我将问题代码分离为GetProjectReferences方法.
我无法参考VSLangProj.VSProject.
DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as
var sol = dte2.Solution;
var projs = sol.Projects;
foreach (Project project in projs)
{
if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder)
{
//Ignoring Solution Folders for now
}
else
{
//This method tries to get the refernces
AppendProject(sb,project);
}
}
private void GetProjectReferences(StringBuilder sb, Project project)
{
var vsProject = project.Object as VSLangProj.VSProject;
var references = vsProject.References as VSLangProj.References;
sb.AppendLine(project.Name + ": " + references.Count);
int counter …Run Code Online (Sandbox Code Playgroud) TimeSpan ts = DateTime.Now.Subtract(DateTime.Parse(reader1["cur_time"].ToString()));
int a = ts.Minutes;
MessageBox.Show(a.ToString());
MessageBox.Show(ts.Milliseconds.ToString());
Run Code Online (Sandbox Code Playgroud)
通过减去时间,它给我8分钟是正确的.但是在毫秒内转换了这8分钟没有给出正确的答案.如果我转换8分钟毫秒,它应该是480000毫秒,但上面的代码给我708回答.
我正在创建一个C#电话簿应用程序,它从用户(名字,姓氏和电话号码)获取输入,将其存储在文本文件中,并可以在Windows窗体上显示.目前,当我启动程序时,我在此方法中得到一个StackOverflowException:
public string Phone
{
get { return Phone; }
set
{ // VS says that StackOverflowException happens here
if (value.Length == 10)
{
Phone = value;
}
else
{
Phone = "0000000000";
}
}
}
Run Code Online (Sandbox Code Playgroud)
我相信当我尝试从文本文件中读取电话号码时会发生异常.以下代码来自Read方法:
foreach (var line in lines)
{
string[] entries = line.Split('`');
Contact newContact = new Contact();
newContact.FirstName = entries[0];
newContact.LastName = entries[1];
newContact.Phone = entries[2]; //I think exception happens here
contactList.Add(newContact);
Run Code Online (Sandbox Code Playgroud)
但是,当我在该行放置一个断点并进入调试模式时,当我将鼠标悬停Phone在该行中时Phone = value;,VS在大约6秒后退出调试模式.这是我悬停Phone和VS退出调试模式后的输出:
ContactsList.vshost.exe'(Managed(v4.0.30319)):已加载'C:\ WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll',跳过加载符号.模块已经过优化,调试器选项"Just My Code"已启用.程序'[5200] …
我试图用C++创建一个简单的.lib文件,尝试使用C++/CLI包装技术在我的C#中使用代码.问题是,我的C++代码本身没有成功编译.它一直在推动"不是一个有效的Win32应用程序"错误.我尝试查找同样的问题,许多答案表明Windows XP存在.NET框架问题.但我在'Visual Studio 2015(v140)'平台工具集上运行它.我的桌面是运行Windows 10 pro的64位操作系统(x64处理器).
这是我的项目属性的片段:
#pragma once
namespace AddTwoNumbersLib
{
class AddClass
{
public:
static double Add(double x, double y);
};
}
Run Code Online (Sandbox Code Playgroud)
这是我的.cpp代码:
#include "AddClass.h"
namespace AddTwoNumbersLib
{
double AddClass::Add(double x, double y)
{
return x + y;
}
}
Run Code Online (Sandbox Code Playgroud)
因为我是业余爱好者,所以我正在努力解决这个问题.非常感谢您的帮助!
我尝试了很多次来修复错误” Incomplete Definition of Type of struct *,请您能帮我找到问题并解决吗?
有什么建议吗?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
struct mypoint;
typedef struct mypoint {
int x;
int y;
};
void setRandomPoint(struct mypoint *a, int min, int max)
{
do {
a->x = rand();
} while (a->x > max || a->x < min);
do
{
a->y = rand();
} while (a->y > max || a->y < min);
}
int main()
{
struct myPoint point;
int min = 0, max = 0;
int i;
srand(time(NULL));
while …Run Code Online (Sandbox Code Playgroud) Simply this problem while trying to run my code. Any help please?
Server Error in '/' Application.
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or …
我有简单的程序:
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 6;
int* p1 = &a;
int* p2 = &b;
std::cout << p1 << " " << p2 << " ,sizeof(int)=" << sizeof(int) << std::endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它产生以下输出:
00DBF9B8 00DBF9AC ,sizeof(int)=4
Run Code Online (Sandbox Code Playgroud)
但是,00DBF9B8 - 00DBF9AC == ?.我无法理解这个结果.
如果我像这样修改程序:
#include <iostream>
using namespace std;
int main()
{
static int a = 5;
static int b = 6;
int* p1 = &a;
int* p2 …Run Code Online (Sandbox Code Playgroud)