RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-221908

Vadim Prokopchuk's questions

Martin Hope
Vadim Prokopchuk
Asked: 2020-01-08 21:23:53 +0000 UTC

确定枚举值的算法如何在 C# 中工作?

  • 1

C# 中的枚举值确定算法在示例中是如何工作的?

主要代码:

void Main()
{
    Numbers number;
    number = Numbers.Four;

    Console.WriteLine((int) number);
    Console.WriteLine(number);
    Console.WriteLine(Numbers.Four);
}

示例 1:

enum Numbers {
    One,
    Two,
    Three,
    Four = 1,
    Five,
    Six
}

将四的值设置为 1

执行结果是:

1 四 四

如果你反编译,你可以看到以下内容:

private enum Numbers
{
    One = 0,
    Two = 1,
    Three = 2,
    Four = 1,
    Five = 2,
    Six = 3
}

示例 2

 enum Numbers {
    One,
    Two,
    Three,
    Four = 2,
    Five,
    Six
 }

为四设置值 2

执行结果是:

2 三 三

反编译后是这样的:

private enum Numbers
{
    One = 0,
    Two = 1,
    Three = 2,
    Four = 2,
    Five = 3,
    Six = 4
}

为什么在第一个例子中选择了最后一个匹配值,而在第二个例子中选择了第一个匹配值?

c#
  • 2 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-03-10 20:13:53 +0000 UTC

什么时候不应该使用迭代器?

  • 0

什么时候使用迭代器模式是合适的,什么时候是不可取的?

模式隐藏了哪些陷阱?

例如,我有一个从文件中读取行的类:

public class FormattedFileReader{
    private readonly string _path;

    // ...     

    public static IEnumerable<string> ReadFromFile(){

        foreach (var line in File.ReadLines(_path)){
            yield return GetFormattedValue(line);
        }
    }

    private string GetFormattedValue(string initial){
        // ...
    }
}
c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-10-27 19:06:36 +0000 UTC

在 C++ 中释放内存

  • 0

有一个类Cinema,以及它的派生词。在控制台应用程序中,我创建了这些类的列表。

auto cinemas = new std::list<Cinema*>();

cinemas->push_back(new ImaxCinema("Victory square 15/6", "Imax 1", 150, 150));
cinemas->push_back(new Cinema3D("Victory square 16/1", "3D-Cinema", "Spectrum", 14));
cinemas->push_back(new DriveInCinema("Victory square 17/89", "Drive-In", 15, 102.3));

后来,通过一个循环,我输出了内容。

for (auto iterator = cinemas->begin(); iterator != cinemas->end(); iterator++)
{
    (*iterator)->write();
} 

然后我清除列表并释放为列表分配的内存。

cinemas->clear();
delete cinemas;

问题:是否对列表中的每个元素都调用了delete ?如何检查?

c++
  • 3 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-05-03 01:47:22 +0000 UTC

C# 中的部分方法

  • 3

部分方法有什么实际用途?

例如,

partial class A
{
    partial void OnSomethingHappened(string s);
}

partial class A
{
    partial void OnSomethingHappened(String s)
    {
        Console.WriteLine("Something happened: {0}", s);
    }
}

部分方法 C#

c#
  • 3 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-05-04 03:02:22 +0000 UTC

渲染局部视图

  • 1

面临呈现异步方法的问题。例如,有一个模板,我们在其中嵌入了一个局部视图

<ul class="nav navbar-nav navbar-right">
   @{ Html.RenderAction("PartialInfo", "Profile"); } (1)
</ul>

该方法PartialInfo是异步的

[ChildActionOnly]
public async Task<PartialViewResult> PartialInfo()
{
   var user = await userService.GetByEmailAsync(User.Identity.Name);
   ...

在第 (1) 行渲染期间发生错误崩溃

HttpServerUtility.Execute 被阻塞,直到异步操作完成执行。

我想知道为什么会出现错误,为什么开发人员禁止异步执行插入方法。


ps 我知道,如果你换成同步版本,那么一切都会 - 好的

asp.net-mvc
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-02-19 22:09:57 +0000 UTC

输入元素不拉伸

  • -1

为什么input元素没有拉伸到父窗口的宽度?右侧没有外部缩进。

在此处输入图像描述

<div class="row">
        <div class="form-group col-xs-12 col-sm-8 col-md-6">
            <input type="text" class="form-control" />
        </div>
</div>

试图重新定义样式input { width: 100%; }- 没有帮助。通过属性在 HTML 中覆盖style- 也无济于事。

html
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-02-01 04:56:22 +0000 UTC

C#中如何正确比较字符串

  • 11

如何在 C# 中正确比较字符串:Equalsor ==?

string str1 = "s";
string str2 = "s";

Console.WriteLine("eq: " + str1.Equals(str2));
Console.WriteLine("==: " + (str1 == str2));

在这两种情况下,结果True都是尽管String是一个类并且运算符==必须比较引用。

IlDasm表明根据方法创建并比较了 2 个变量Equals,== (op_Equality)

  IL_0000:  nop
  IL_0001:  ldstr      "s"
  IL_0006:  stloc.0
  IL_0007:  ldstr      "s"
  IL_000c:  stloc.1
  IL_000d:  ldstr      "eq: "
  IL_0012:  ldloc.0
  IL_0013:  ldloc.1
  IL_0014:  callvirt   instance bool [mscorlib]System.String::Equals(string)
  IL_0019:  box        [mscorlib]System.Boolean
  IL_001e:  call       string [mscorlib]System.String::Concat(object, object)
  IL_0023:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_0028:  nop
  IL_0029:  ldstr      "==: "
  IL_002e:  ldloc.0
  IL_002f:  ldloc.1
  IL_0030:  call       bool [mscorlib]System.String::op_Equality(string, string)
  IL_0035:  box        [mscorlib]System.Boolean
  IL_003a:  call       string [mscorlib]System.String::Concat(object, object)
c#
  • 3 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-26 23:40:28 +0000 UTC

将元素附加到链接

  • 1

如何在保留虚拟路径的同时在ASP.NET MVC中嵌套元素?

@Html.ActionLink(@ProjectName, "Index", "Home")

那些。此方法将检查路由器设置并返回有效路径,即使路由方案发生变化,这与<a href="/Home/Index/">... </a>

期望的结果: <a href="/Home/Index" .... > Text <i>..</i></a>

尝试过: <a href="@Url.Content("/Home/Index") ...">Text<i>...</i></a> - 返回所需的结果,但在我看来这并不完全正确。

告诉我如何正确地做。

c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-25 04:11:10 +0000 UTC

初始化 C# 结构

  • 9

为什么在有构造函数的情况下还要初始化C#值类型中的所有字段?

例如,下面的代码将不会编译

struct AAA
{
    public int A;
    public string C;

    public AAA(int a)
    {
        A = a;
    }
}

AAA.C 字段必须在控制返回到调用方法之前完全限定。

但是如果我们删除构造函数,那么一切都会编译

struct AAA
{
    public int A;
    public string C;
}
c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-20 01:01:07 +0000 UTC

ASP.NET 配置文件

  • 0

ASP.NET 中的配置文件提供程序有什么用?他们有什么好处?HttpContext.Profile和之间有什么区别Session?

c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-17 03:46:25 +0000 UTC

回滚方法 EntityFramework

  • 2

请告诉我如何实现RollbackusingEntityFramework 6.x以及工作单元模式。为此有一个接口类。IUnitOfWork

public interface IUnitOfWork : IDisposable
{
   void Commit();
   // void Rollback();
}

和类 -UnitOfWork

    public class UnitOfWork : IUnitOfWork 
    {
        public DbContext Context { get; private set; }

        public UnitOfWork(DbContext context)
        {
            Context = context;
        }

        public void Commit()
        {            
            if (Context != null)
            {
                Context.SaveChanges();
            }
        }

        public void Dispose()
        {
            if (Context != null)
            {
                Context.Dispose();
            }
        }
    }

我知道在 T-SQL 级别是这样设置的:

BEGIN TRANSACTION
  // операции взаимодействия
  IF (@@error <> 0)
        ROLLBACK
COMMIT

更新程序

计划使用

try
{
    repository.Delete(...);
    unitOfWork.Commit();
}
catch
{
   unitOfWork.Rollback();
   // регистрация ошибки
}
c#
  • 2 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-12 05:25:54 +0000 UTC

接口与抽象类[重复]

  • 2
这个问题已经在这里得到回答:
Differences between an abstract class and an interface(抽象类和接口) (13个答案)
5 年前关闭。

你好社区。C#中的抽象类和接口有什么区别?毕竟,我们可以说一个抽象类,其中所有方法都没有实现并被标记为抽象,在某种程度上是一个接口。是的,有一个显着的区别——接口描述了对象的行为,即 它必须完全实现,不像抽象类,在抽象类中,不实现抽象方法,继承人也将成为抽象类。我的理解是接口描述了一般的行为而没有实现(每个类都有自己的),那么抽象类是干什么的呢?

c#
  • 2 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-09 03:56:55 +0000 UTC

业务逻辑层和数据访问层有什么区别

  • 2

有这样一个应用架构:

在此处输入图像描述

DAL 实现了两种模式:Repository 和 UnitOfWork。为此,使用了 ORM。ORM 类、DAL 类和 BLL 类之间有什么区别?或者在 DAL 中已经只描述了实体?举例说明。根据我的错误推理,DTO 类原来与 ORM 相同。纠正我。

архитектура
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-01-05 04:41:04 +0000 UTC

C# 代表。调用

  • 2

让我们以下面的代码为例,跳过所有细节。

private void Example(Func<bool> exampleFunction)
{
    bool result = exampleFunction();    // 1
    result = exampleFunction.Invoke();  // 2
}

第一次和第二次函数调用有什么区别?描述使用第一次或第二次委托调用很重要的情况。

在 MSDN 上它说:

使用指定参数调用当前实例表示的方法或构造函数。

c#
  • 2 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-12-25 20:02:41 +0000 UTC

在 PowerShell 中显示执行信息

  • 2

下午好。有一个用 C# 编写的文件,例如“app.cs”。您需要通过 C# 中的应用程序编译此文件。如果编译器给出编译错误,那么你需要将输出重定向到一个文本文件。问题是从 C# 执行了一个 PowerShell 脚本,在该脚本中启动了编译器本身。我不太了解 PowerShell,这就是我求助于社区的原因。这是下面的代码:

  • PowerShell脚本代码

@"Start-Process -FilePath 'C:\Program Files\MSBuild\12.0\Bin\csc.exe' -ArgumentList 'app.cs' -Wait -NoNewWindow | Out-File -FilePath log.txt"

  • C#代码

    string script = ... // см. выше 
    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(script);   
    Collection<PSObject> result = pipeline.Invoke();
    runspace.Close();
    

ps 结果变量也为空。

c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-10-28 00:49:46 +0000 UTC

泛型方法的类型约束

  • 2

如何在 C# 中为泛型方法设置仅对整数类型的限制(byte、sbyte、short、ushort、int、uint、long、ulong)

public T example<T>(this T value) where T (...)???? 
c#
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-10-15 08:57:21 +0000 UTC

MS SQL SERVER - 数据库查询

  • 3

假设数据库中有一个简单的表,其中包含字段 ID、Name。还有通过实体框架与数据库的连接。问题:如何正确选择以下示例的LINQ to SQL转换有何不同:

...Examples.FirstOrDefault(ex => ex.name.Equals(parameter))

和

...Examples.Where(ex => ex.name.Equals(parameter)).FirstOrDefault()

public class EFDbContext : DbContext
{
    public DbSet<Example> Examples { get; set; }
}

public class Example
{
    public int Id { get; set; }
    public string Name { get; set; }
}
sql-server
  • 1 个回答
  • 10 Views
Martin Hope
Vadim Prokopchuk
Asked: 2020-10-03 04:08:52 +0000 UTC

Visual Studio 2013 中的代码突出显示

  • 1

你好社区。这个问题可能被问过不止一次。由于我无法正确谷歌并找到答案,所以我会写在这里。

实际上问题本身是:如何在 Visual Studio 2013 Ultimate for Web Applications 中禁用代码背景突出显示,以便 C# 背景代​​码与 HTML 背景相同,即在编写 HTML & C# 代码 (.cshtml) 的文件中. 我会留下一张照片作为例子。

图片

visual-studio-2013
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5