.net

The role of BeginInit() and EndInit() methods in Designer

社会主义新天地 提交于 2021-02-04 22:11:49
问题 I've red that those methods of ISupportInitialize interface are used by Designer to support optimization, to ensure atomicity of initialization of controls, and to prevent any action on controls during initialization. My questions are: In what way they help Designer to optimize initialization of controls? Why to ensure atomicity of initialization? Is there any reasonable example when to use them in code not generated by Designer? 回答1: It does not have anything to do with optimization.

How to pass arguments to an HtmlFile?

北城以北 提交于 2021-02-04 21:53:08
问题 How to pass arguments to an HtmlFile from C#? Like: System.Diagnostics.Process.Start("Sample.html","Arguments"); If I execute the above code the "Sample.html" file should be opened and it should do something with the "arguments". 回答1: Process.Start( @"C:\Program Files\Internet Explorer\iexplore.exe", "file:///c:/path/to/file/Sample.html?param1=value1" ); UPDATE: To figure out the default browser location: class Program { [DllImport("shell32.dll")] public extern static int FindExecutable(

Why are content files from NuGet packages added as links in .NET Core projects and how can you prevent that?

余生长醉 提交于 2021-02-04 21:48:57
问题 I am developing a .NET Standard library and plan to use it in both .NET Core and .NET Framework projects. My library is dependant on a third library which itself is dependant on a few C binary files. The C binary files have to be copied to the output directory of the project which will be referencing my library. I added the binary files to my library project as content and they are copied to the content and contentFiles directories when the NuGet package is packed with the dotnet pack command

How to parse datetime with DateTime.ParseExact

三世轮回 提交于 2021-02-04 21:36:17
问题 I have the following string that I need to parse string date = "2017-06-23T13:45:45.816" What is correct format string? I tried DateTime createDate = DateTime.ParseExact(date, "yyyy-MM-dd'T'hh-mm-ss", CultureInfo.InvariantCulture); 回答1: yyyy-MM-dd'T'hh-mm-ss is not 2017-06-23T13:45:45.816 you have missing milliseconds, 12 hour clock and also wrong separators. You'd probably need something like: "yyyy-MM-dd'T'HH:mm:ss.fff" Remember it's ParseExact . 回答2: That seems an RFC 3339 date to me, so

How to parse datetime with DateTime.ParseExact

假如想象 提交于 2021-02-04 21:36:06
问题 I have the following string that I need to parse string date = "2017-06-23T13:45:45.816" What is correct format string? I tried DateTime createDate = DateTime.ParseExact(date, "yyyy-MM-dd'T'hh-mm-ss", CultureInfo.InvariantCulture); 回答1: yyyy-MM-dd'T'hh-mm-ss is not 2017-06-23T13:45:45.816 you have missing milliseconds, 12 hour clock and also wrong separators. You'd probably need something like: "yyyy-MM-dd'T'HH:mm:ss.fff" Remember it's ParseExact . 回答2: That seems an RFC 3339 date to me, so

Interop with Microsoft Access does not interact with User's session

ε祈祈猫儿з 提交于 2021-02-04 21:16:18
问题 I am injecting a piece of VBA code into a Microsoft Access database from .Net. It is just a single line of code, which runs a Macro. All the Macro does is run a block of VBA code inside a module. The issue I am having is that this all happens in a new MSAccess session, which I can't even see, instead of the session the user currently has open. Is it possible to, instead, have this interact with the users current MSAccess session? The whole point of this is to open a particular form inside the

new method declaration in derived interface

笑着哭i 提交于 2021-02-04 21:10:30
问题 I lately studied some code and encountered a derived interface that declares new method with exactly the same name and signature as a base interface: public interface IBase { Result Process(Settings settings); } public interface IDerived : IBase { new Result Process(Settings settings); } I'm wondering if there could be a reason for this. According to my understanding I can safely remove the latter method declaration and leave IDerived empty without possibly breaking any code using it. Am I

new method declaration in derived interface

邮差的信 提交于 2021-02-04 21:10:04
问题 I lately studied some code and encountered a derived interface that declares new method with exactly the same name and signature as a base interface: public interface IBase { Result Process(Settings settings); } public interface IDerived : IBase { new Result Process(Settings settings); } I'm wondering if there could be a reason for this. According to my understanding I can safely remove the latter method declaration and leave IDerived empty without possibly breaking any code using it. Am I

Internal conversion of integer to char whose size is smaller

一笑奈何 提交于 2021-02-04 21:07:17
问题 In the following program , I am assigning a integer data type to a char data type. public static void main(String args[]) { char ch =65; System.out.println(ch); } I know the fact that int occupies 32 bits and char occupies 16 bits . With that knowledge , I was expecting the compiler throw an error of some message "Attempt to convert a data of higher size to a lower size ". Why is the compiler not complaining and internally converting and printing the output as 'A' (I understand the fact that

Regex for only hours or hours and minutes

早过忘川 提交于 2021-02-04 20:42:05
问题 I am using regex ^(([0-9])|([0-1][0-9])|([2][0-3])):(([0-9])|([0-5][0-9]))$ for time. It is very good regex but when user wants to enter only hours like 8 or 12 without colon and minutes it is not allowing. Can any one suggests which regular expressions suits hours only or hours:minutes. 回答1: ^(([0-9])|([0-1][0-9])|([2][0-3]))(:(([0-9])|([0-5][0-9])))?$ made the ":mm" part optional by putting it in () and adding a ? quantifier. 回答2: Just make the last part optional, like this: ^(([0-9])|([0-1