在.NET 2.0 C#应用程序中,我使用以下代码来检测操作系统平台:
string os_platform = System.Environment.OSVersion.Platform.ToString();
Run Code Online (Sandbox Code Playgroud)
这将返回"Win32NT".问题是,即使在Windows Vista 64位上运行,它也会返回"Win32NT".
有没有其他方法可以知道正确的平台(32或64位)?
请注意,在Windows 64位上作为32位应用程序运行时,它还应检测64位.
如何指定传递给orderby使用我作为参数的值的参数?
例如:
List<Student> existingStudends = new List<Student>{ new Student {...}, new Student {...}}
Run Code Online (Sandbox Code Playgroud)
目前实施:
List<Student> orderbyAddress = existingStudends.OrderBy(c => c.Address).ToList();
Run Code Online (Sandbox Code Playgroud)
而不是c.Address,我如何将其作为参数?
例
string param = "City";
List<Student> orderbyAddress = existingStudends.OrderByDescending(c => param).ToList();
Run Code Online (Sandbox Code Playgroud) 我试图用另一个字符串替换字符串的一部分.更确切地说,我有 C:\Users\Desktop\Project\bin\Debug
我试图取代\bin\Debug 与\Resources\People
我尝试过以下方法:
path.Replace(@"\bin\Debug", @"\Resource\People\VisitingFaculty.txt");
path.Replace("\\bin\\Debug", "\\Resource\\People\\VisitingFaculty.txt");
以上两者似乎都不起作用,因为字符串保持不变并且没有任何替换.难道我做错了什么?
鉴于 auto 属性编译为 a get_method、 aset_method和私有变量,并且自 C# 8 引入默认接口方法以来
接口中的属性可以有默认实现吗?
特别是仅获取属性?
我正在寻找一种方法将字符串文本追加到Windows应用商店应用程序中的文件.我已经尝试读取该文件,然后创建一个新文件来覆盖它,但Windows Store Apps C#不能像C一样工作,在创建具有相同名称的新文件时会覆盖旧文件.目前我的代码是打开旧文件,读取它的内容,删除它并创建一个新文件,其中包含我读过的内容以及我想要追加的内容.我知道有更好的方法,但我似乎无法找到它.那么我如何将文本附加到Windows应用商店应用程序(Windows RT)中已存在的文件?
编辑 -
我试过这个
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("feedlist.txt");
await Windows.Storage.FileIO.AppendTextAsync(file, s);
Run Code Online (Sandbox Code Playgroud)
但我继续System.UnauthorizedAccessException
根据MSDN 得到这种情况,当文件是只读时(我检查右键单击属性,它不是),如果我没有必要的权限来访问该文件我该怎么办?
可能重复:
获取相对于当前工作目录的路径?
我在C#中有代码,包括从绝对路径到相对的一些图像,因此无论应用程序折叠位于何处,都可以找到图像.
例如,我的代码(以及我的笔记本电脑中的图像)中的路径是
C:/something/res/images/image1.jpeg
Run Code Online (Sandbox Code Playgroud)
我想要我的代码中的路径
..../images/image1.jpeg
Run Code Online (Sandbox Code Playgroud)
因此它可以在放置文件夹的任何地方运行,无论C:分区的名称是什么等.
我希望在我的代码中有一个独立于应用程序文件夹位置的路径,或者它是否在另一个分区中,只要它与解决方案的其余部分位于同一文件夹中.
我有这个代码:
try
{
File.Delete("C:/JPD/SCRAT/Desktop/Project/Resources/images/image1.jpeg");
}
catch (Exception)
{
MessageBox.Show("File not found:C:/Users/JPD/Desktop/Project/images/image1.jpeg");
}
Run Code Online (Sandbox Code Playgroud)
此代码仅在文件和文件夹位于该特定路径时运行(也是代码的位置)我希望该路径是相对的,所以无论我把整个文件夹(代码,文件等)放在哪里,程序仍然会只要代码(在项目文件夹下)与文件夹图像位于同一位置就可以工作......我该怎么办?
我使用C#和ASP.NET 4 WebControls.
我的页面上有一个TextBox,用户可以输入HEXADECIMAL格式(ff0000)或HTML格式("红色")的HTML颜色.
我最初的想法是编写一个能够验证此用户输入的RegEx会很困难,所以我想出了一个简单的方法来检查输入的颜色是否可以转换为有效的方法来使用System.Drawing中.
在我的代码下面.它返回一个Bool DataType,说明操作是否成功.它现在工作正常,但我想知道:
谢谢你的考虑.
using SD = System.Drawing;
protected static bool CheckValidFormatHtmlColor(string inputColor)
{
try
{
SD.Color myColor = SD.ColorTranslator.FromHtml(inputColor);
return true;
}
catch (Exception ex)
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud) 我需要知道一种方法来调整图像大小以适应盒子而不会使图像拉伸太多.盒子设置了宽度和高度,我希望图像尽可能多地填充盒子,但保持它原来的宽高比.
我正在阅读C#6.0中引入的更改,我对null运算符有疑问.
在C#6中这个表达式
int? x= y?.length;
Run Code Online (Sandbox Code Playgroud)
将是有效的,如果y是,null并返回一个null.没有NullargumentException将提高.我认为这是对语言的一个很好的补充.它删除了额外的检查和难看的代码.
但是在null条件运算符的情况下,我们可能会有如下代码
int? x= y?.length ?? 0;
Run Code Online (Sandbox Code Playgroud)
如果y是null则0返回.如果length是null,会发生什么?它又返回零?
我得到了上述错误和大约101个错误(共102个错误).我搜索过,我找到的唯一解决方案是在gl.h之前包含windows.h库.但我已经这样做了.那么解决方案是什么?谁能帮我?我正在使用过剩和opengl.以下是我的包含流程.如果您要求我提供更多代码,请告诉我
#include <stdio.h> // Standard C/C++ Input-Output
#include <math.h> // Math Functions
#include <windows.h> // Standard Header For MSWindows Applications
#include <GL/gl.h>
#include <time.h>
#include <stdlib.h>
#include "SOIL.h"
Run Code Online (Sandbox Code Playgroud)
这是完整的错误列表:
Error 1 error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error 2 error C2085: 'APIENTRY' : not in formal parameter list c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error 3 error C2146: syntax error : missing ',' before identifier 'glAccum' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error 4 error C2143: …Run Code Online (Sandbox Code Playgroud)