string s = "";
for(int i=0;i<10;i++) {
s = s + i;
}
Run Code Online (Sandbox Code Playgroud)
我一直是这些选择来回答这个问题.
我有这个简单的代码,我只想知道这个代码将创建多少个字符串对象.
我有一个疑问,是string s = "";
没有创造任何对象.我不这么认为,请让我说清楚.
如果我用+运算符追加字符串,它会创建新的字符串,所以我认为它将是在for循环的每次迭代中创建的新对象.
所以我认为会创建11个对象.让我知道如果我不对.
String result = "1" + "2" + "3" + "4"; //Compiler will optimise this code to the below line.
String result = "1234"; //So in this case only 1 object will be created??
Run Code Online (Sandbox Code Playgroud)
我按照下面的链接,但仍然不清楚.
请覆盖string str
和string str = null
案例.如果我们不初始化字符串以及何时将字符串赋值为null,会发生什么.所以在这两种情况下它将是一个对象或没有对象.
string str;
string str = null;
Run Code Online (Sandbox Code Playgroud)
稍后在代码中,如果我这样做.
str = …
Run Code Online (Sandbox Code Playgroud) 大家好,我正在尝试在.net core api中执行JWT,并且在文件startup.cs中配置JWT时有一个问题具体来说,我想问“ValidIssuer”和“ValidAudience”要做什么,这对JWT意味着什么?有人可以帮助我吗,谢谢大家。
这是我的代码:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(option =>
{
option.TokenValidationParameters = new TokenValidationParameters
{
// what to validate
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuerSigningKey = true,
// set up validate data
ValidIssuer = "smesk.in",
ValidAudience = "reader",
IssuerSigningKey = symmetricSecurityKey
};
});
Run Code Online (Sandbox Code Playgroud) 我需要使用ProblemDetails来验证错误。它按预期工作。但这里有一个大问题,我必须在所有操作方法中编写类似的代码,我认为这不是一个好主意。
public async Task<ActionResult<SampleResponse>> Post([FromBody] SampleRequest getRateApiRequest)
{
try
{
if (ModelState.IsValid == false)
{
ProblemDetails problemDetails = new ProblemDetails();
problemDetails.Detail = "Detail";
problemDetails.Instance = "Instance";
problemDetails.Status = StatusCodes.Status400BadRequest;
problemDetails.Title = "Title";
problemDetails.Type = "Type";
List<FieldCodeMessage> codeMessages = new List<FieldCodeMessage>();
foreach (var modelState in ModelState)
{
if (modelState.Value.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
MemberInfo property = typeof(TradeBookingRequestAPI).GetProperty(modelState.Key);
var attribute = property.GetCustomAttributes(typeof(DisplayNameAttribute), true).Cast<DisplayNameAttribute>().Single();
string displayName = attribute.DisplayName;
switch (modelState.Key)
{
case "Property1":
codeMessages.Add(new FieldCodeMessage(field: displayName, code: "01", message: modelState.Value.Errors.Select(a => a.ErrorMessage).FirstOrDefault())); …
Run Code Online (Sandbox Code Playgroud) 我想更改 C# 应用程序的同一解决方案下所有项目的输出路径。我正在为所有项目一一手动设置。大约有 40 个项目,因此对所有项目都这样做非常重要。我需要经常更改此输出路径。
我有一种方法可以通过运行一个脚本来执行此操作,该脚本将为该解决方案文件下的所有文件设置输出csproj
路径。ADir
BDir
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PFx86|x86'">
<OutputPath>ADir</OutputPath>
Run Code Online (Sandbox Code Playgroud)
或者我可以创建一个新Configuration
的ADir
.
那么在 Visual Studio 2015 中是否有任何快捷方式可以做到这一点?
我在数据库中有一些主数据,我在整个应用程序中都需要这些数据。那么在应用程序中定义这些数据的最佳方式是什么?我应该在应用程序中在哪里定义,以便每次应用程序启动时我都会在应用程序中初始化此主数据。我应该在哪里定义从数据库获取数据的方法?
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Runtime.Caching;
using Test.Authorization;
using Test.Caching.Dto;
namespace Test.Caching
{
[AbpAuthorize(AppPermissions.Pages_Administration_Host_Maintenance)]
public class CachingAppService : TestAppServiceBase, ICachingAppService
{
private readonly ICacheManager _cacheManager;
public CachingAppService(ICacheManager cacheManager)
{
_cacheManager = cacheManager;
}
public ListResultDto<CacheDto> GetAllCaches()
{
var caches = _cacheManager.GetAllCaches()
.Select(cache => new CacheDto
{
Name = cache.Name
})
.ToList();
return new ListResultDto<CacheDto>(caches);
}
public async Task ClearCache(EntityDto<string> input)
{
var cache = _cacheManager.GetCache(input.Id);
await cache.ClearAsync();
}
public async Task ClearAllCaches()
{
var caches …
Run Code Online (Sandbox Code Playgroud) 我必须调用一个从多个表中选择记录的存储过程。
我尝试了以下代码,但它为实体类以外的其他表中的列返回 null。
private async Task<IEnumerable<TEntity>> InvokeStoredProcedureAsync(string input = "")
{
var storedProcedureName = "sp_BulkSelect";
using (var db = new MyDbContext(_options))
{
var result = await db.Set<TEntity>().FromSql(storedProcedureName + " @inputIds", new SqlParameter("inputIds", input)).ToListAsync();
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
存储过程:
SELECT
[MainTable].[Id],
[Table1Id],
[Table2Id],
[MainTable].[Table1Code],
[Table2].[Table2Code]
FROM
[MainTable] [MainTable]
LEFT JOIN
[Table1] [Table1] ON [MainTable].Table1Id = [Table1].[Id]
LEFT JOIN
[Table2] [Table2] ON [MainTable].[Table2Id] = [Table2].[Id];
Run Code Online (Sandbox Code Playgroud)
MainTable
班级:
[Table("MainTable")]
public class MainTable : FullAuditedEntity
{
[ForeignKey("Table1Id")]
public virtual Table1 Table1 { get; set; …
Run Code Online (Sandbox Code Playgroud) c# entity-framework ef-code-first entity-framework-core asp.net-core
我不确定这个主题是否真的有意义,但我不确定如何说出来.这是设置:我有一个Item
,有很多ItemLogic
,每个都有一个Field
.Item
例如,每个ItemLogic
实体都有25个实体.逻辑确定是否Item
匹配表单中的给定输入.例如,Field X has a value greater than A
和Field Y has a value equal to B
等每个25场.
在当前版本的应用程序中,查询并循环所有相关实体,返回所有ItemLogic所在的第一个匹配项true
.它有点贵,但代码简单,而且从来没有那么多项目要看.到现在.
现在,该应用需要过滤3000个项目才能找到匹配项.上一个查询至少有两个连接,在我们的SQL实例上大约需要45秒.这太长了.
存储过程看起来很自然,但这里有一个问题:数据对于每组Items都是动态的,它以字符串值的形式出现,并且通常需要被转换为不同的类型(DateTime或int最常见)来执行实际的比较,一些逻辑被忽略而不是比较.这是存储过程中的大量额外开销,至少它是如何打击我的.
或者,我可以对数据进行分块,但这对于试图匹配集合中最后一个项目的可怜人来说并没有太大的节省.
有什么方法可以加速比赛?
架构和一些示例数据:
CREATE TABLE [dbo].[Items](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](255) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[ItemLogic](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ItemId] [int] NOT NULL,
[FieldId] [int] NOT NULL,
[Value] [nvarchar](max) NULL,
[Comparison] [int] NOT NULL
) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为类型文本的输入实现相同的CSS,类似于我们在CreateUser默认页面中的类型.因此,当您单击"用户名"文本框时,它下方会显示一条蓝线.同样我在我的页面上尝试它工作正常,但当我转到其他页面并再次来到此页面时,它不显示文本框下的蓝线.
创建-user.component
<div bsModal #createUserModal="bs-modal" class="modal fade" (onShown)="onShown()" tabindex="-1" role="dialog" aria-labelledby="createUserModal" aria-hidden="true" [config]="{backdrop: 'static'}">
<div class="modal-dialog">
<div #modalContent class="modal-content">
<form *ngIf="active" #createUserForm="ngForm" id="frm_create_user" novalidate (ngSubmit)="save()">
<div class="modal-header">
<button type="button" class="close" (click)="close()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">
<span>{{l("CreateNewUser")}}</span>
</h4>
</div>
<div class="modal-body">
<ul class="nav nav-tabs tab-nav-right" role="tablist">
<li role="presentation" class="active"><a href="#user-details" data-toggle="tab">User Details</a></li>
<li role="presentation"><a href="#user-roles" data-toggle="tab">User Roles</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane animated fadeIn active" id="user-details">
<div class="row clearfix" style="margin-top:10px;">
<div class="col-sm-12">
<div class="form-group form-float">
<div class="form-line">
<input …
Run Code Online (Sandbox Code Playgroud) 我想请求您帮助使用Bogus Faker。
我有这个
private readonly Faker _faker;
_faker = new Faker("fr");
List<string> _randomString = (List<string>)_faker.Make(3, () => _faker.Random.Word()); // OK
List<string[]> _randomStrinArray = (List<string[]>)_faker.Make(3, () => _faker.Random.Word()); // KO
Run Code Online (Sandbox Code Playgroud) 当我单击 NuGet 包管理器中的任何包时,我看到消息“包源映射在 Visual Studio 2022 17.8.0 中已关闭” 。
当我单击“配置”链接时,它会打开以下窗口。
我也想问这个错误是什么意思?为什么我会看到这个错误?我需要修复它还是可以忽略它?