这对某些人来说似乎是一个愚蠢的问题,但我需要将一个双精度数转换成十进制来用作货币.M去哪儿了?
decimal dtot = (decimal)(doubleTotal);
Run Code Online (Sandbox Code Playgroud) 是否可以使用C#中的显式类型转换将基类对象分配给派生类引用?
我试过它,它会产生运行时错误.
我正在寻找一个可以输出对象及其所有叶值的类,其格式类似于:
User
- Name: Gordon
- Age : 60
- WorkAddress
- Street: 10 Downing Street
- Town: London
- Country: UK
- HomeAddresses[0]
...
- HomeAddresses[1]
...
Run Code Online (Sandbox Code Playgroud)
(或更清晰的格式).这相当于:
public class User
{
public string Name { get;set; }
public int Age { get;set; }
public Address WorkAddress { get;set; }
public List<Address> HomeAddresses { get;set; }
}
public class Address
{
public string Street { get;set; }
public string Town { get;set; }
public string Country { get;set; } …Run Code Online (Sandbox Code Playgroud) 通过单击Run或按下运行我的程序时Ctrl + F5,是否可以根据某些检查条件打开不同的窗口?
即如果满足某些条件我想打开一个特定的窗口,但如果不是我想打开另一个窗口.
它应该像打开任何一个窗口之前一样,首先要检查条件
if(File.Exists(<path-to-file>)
Open Window 1
else
Open Window 2
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我今天安装了 vs 2022,当运行我的项目时,我突然发现所有这些请求都在我的 Web 前端中触发
https://dc.services.visualstudio.com/v2/track
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么升级到 2022 后会突然开始发生这种情况?
我不想在本地开发环境中看到这些请求。我怎样才能删除它们?
我尝试选中此框,但没有帮助:
我还尝试右键单击后忽略 AI 依赖项Project -> Configure Application Insights,但这似乎没有任何作用:
我正在使用dotnet core 2.1中的角度SPA应用程序的"新"项目模板,如文章中所述使用Angular项目模板和ASP.NET Core.
但是这篇文章没有提到保护SPA本身的任何内容.我找到的所有信息都是关于保护WEBAPI,但首先我对保护SPA感兴趣.
这意味着:当我打开我的SPA时,例如https:// localhost:44329 /我希望立即重定向到授权服务器,而不是单击某个将执行身份验证的按钮.
背景:
当前的方法是实施需要经过身份验证的用户的MVC策略.但这只能应用于MVC控制器.这就是我添加HomeController以满足第一个请求的原因.
见项目结构:
我的Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "CustomScheme";
})
.AddCookie()
.AddOAuth("CustomScheme", options =>
{
// Removed for brevity
});
services.AddMvc(config =>
{
// Require a authenticated user
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
config.Filters.Add(new AuthorizeFilter(policy));
});
// In production, the …Run Code Online (Sandbox Code Playgroud) 我无法ExtendedExecution正常工作.问题是Revoked在执行完成之前不会触发事件.如果我们采样:
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
Debug.WriteLine("Suspending in app");
var deferral = e.SuspendingOperation.GetDeferral();
using (var session = new ExtendedExecutionSession())
{
session.Reason = ExtendedExecutionReason.SavingData;
session.Description = "Upload Data";
session.Revoked += (s, a) => { Debug.WriteLine($"Extended execution revoked because of {a.Reason}"); };
var result = await session.RequestExtensionAsync();
if (result == ExtendedExecutionResult.Denied) Debug.WriteLine("Extended execution failed");
else
{
Debug.WriteLine("Executing");
await Task.Run(() => { Task.Delay(9000).Wait(); Debug.WriteLine("Finished the task"); });
Debug.WriteLine("Executing finished");
}
Debug.WriteLine("Suspending after execution");
}
deferral.Complete();
} …Run Code Online (Sandbox Code Playgroud) 我有一个使用 .NET Standard 2.1 和 .NET core 3.1 的项目 - 所以 C# 版本是 8.0
根据我发现的几篇文章(例如one , two),应该可以record使用以下语法定义类型:
public class MyRecord(string Input1, int Input2);
Run Code Online (Sandbox Code Playgroud)
但是我遇到了很多编译错误,因为这种定义类的语法显然是不正确的。
这些文章有误导性吗?
是使用记录升级到 C# 9.0,进而升级到 .NET 5.0 的唯一方法吗?
该Directory.EnumerateFiles方法的默认读取顺序是什么?它一致吗?
根据我的经验到目前为止,似乎是在文件创建之日,但我无法找到确认信息.
我问的原因是因为我正在处理的程序的一部分将二进制文件从目录加载到对象中,而这些对象又被加载到数组中.这些对象通过索引数组相互引用,这意味着它们加载到数组中的顺序需要保持一致(以避免转移索引).
我在这里时,还有另一个小问题.删除文件时,无论我做什么,它都会明显改变加载到数组中的文件的索引.有什么建议可以避免这个问题?由于担心存储问题,我之前一直避免使用字典(如果我可以避免存储,则宁愿不存储文本键数组)但如果这是唯一可行的方法,我可能还是要实现它.
编辑:在你的答案的优秀提示后,我已经使用文件的名称重构了字典方法.性能影响相当微不足道,可读性和可维护性都得到了极大的改善,因此效果非常好.
我想展示我的桌面应用程序的发布版本.我正在尝试使用此代码:
_appVersion.Content = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Run Code Online (Sandbox Code Playgroud)
问题是我没有得到我在项目属性中的发布版本.下面是它的截图:
但我得到了3.0.0.12546.有人知道问题在哪里吗?
c# ×10
asp.net-core ×2
casting ×2
.net ×1
.net-core ×1
angular ×1
arrays ×1
base-class ×1
c#-8.0 ×1
c#-9.0 ×1
currency ×1
decimal ×1
explicit ×1
file ×1
ienumerable ×1
indexing ×1
record ×1
wpf ×1
wpf-controls ×1