c#-2.0

GetType() and Typeof() in C#

百般思念 提交于 2019-12-09 03:43:30
问题 itemVal = "0"; res = int.TryParse(itemVal, out num); if ((res == true) && (num.GetType() == typeof(byte))) return true; else return false; // goes here when I debugging. Why num.GetType() == typeof(byte) does not return true ? 回答1: Because num is an int , not a byte . GetType() gets the System.Type of the object at runtime. In this case, it's the same as typeof(int) , since num is an int . typeof() gets the System.Type object of a type at compile-time. Your comment indicates you're trying to

The type or namespace could not be found

房东的猫 提交于 2019-12-09 03:18:53
问题 I'm currently trying to convert a WiX 3.5 custom actions project in Visual Studio 2008 to WiX 3.7 and Visual Studio 2012 and I'm getting the following exception: The type or namespace name 'MyNamespace' could not be found (are you missing a using directive or an assembly reference?) The dll is definitely referenced and Visual Studio 2012 has no problem seeing the namespace. Everything under the namespace even pops up in Intellisense, but when I build it I'm getting this exception. Anyone have

Logging done right

戏子无情 提交于 2019-12-08 17:45:28
问题 So my problem is about logging, and how to handle the log statements which can have influence on your code and your runtime behavior. Log files... every program should write those for propper problem solving but how to do it right? The most log-statements are verry expensive to get because they should provide usefull information and they are always built even the logging is disabled totaly. The logging can be configured by xmls, inCode or in some settings etc. but this doesn't solve the

How to round double values but keep trailing zeros

谁说我不能喝 提交于 2019-12-08 17:11:22
问题 In C# I want a function that rounds a given double to a given amount of decimals. I always want my function to return a value (which can be a string) with the given amount of decimals. If necessary, trailing zeros need to be added. Example: string result = MyRoundingFunction(1.01234567, 3); // this must return "1.012" That's easy, it's just rounding and converting to string. But here comes the problem: string result2 = MyRoundingFuntion(1.01, 3); // this must return "1.010" Is there a

rdlc print auto generate

ⅰ亾dé卋堺 提交于 2019-12-08 09:10:45
问题 I am developing the window application using C#. I am using the reportviewer to display rdlc. I just require following things: 1). Print rdlc without viewing it Client will click on print button and print should go System default printer. 2). if System default printer is not available/working then it will prompt for alternative. i don't want to use xml file 回答1: Here is what you need to do is load your report and data into the report viewer and then render the report pages into list of memory

Event Log SecurityException for Web Application?

☆樱花仙子☆ 提交于 2019-12-08 06:52:39
问题 I have an app that writes messages to the event log. The source I'm passing in to EventLog.WriteEntry does not exist, so the Framework tries to create the source by adding it to the registry. It works fine if the user is an Admin by I get the following whe the user is not an admin: "System.Security.SecurityException : Requested registry access is not allowed." message. How can I fix that? Update I have create the registry with the Admin account manually in the registry. Now, I have the error

How to enum 32bit process's modules from a 64bit application

时光怂恿深爱的人放手 提交于 2019-12-08 05:38:45
问题 I have the code: foreach (var process in Process.GetProcesses()) { if (process.ProcessName.ToLowerInvariant().StartsWith("iexplore")) { foreach (ProcessModule module in process.Modules) { string descr = module.FileVersionInfo.FileDescription; MessageBox.Show(module.FileName); } } } My app is set on "Any CPU" configuration, so it should run as 64bit process on my Win7 x64. I tried to enumerate iexplore.exe's modules (the 32bit version). My question is how to enum the modules of 32bit apps from

What's the fastest way to ReadProcessMemory?

可紊 提交于 2019-12-08 03:52:49
问题 I'm trying to search for all instances of a null-terminated string the memory of a process. I enumed all the alloced memory areas with VirtualQueryEx, then I read them with ReadProcessMemory to a byte array and search using this algo (which I found here and the author claims to be the fastest) public static unsafe List<long> IndexesOf(byte[] Haystack, byte[] Needle) { List<long> Indexes = new List<long>(); fixed (byte* H = Haystack) fixed (byte* N = Needle) { long i = 0; for (byte* hNext = H,

C# - Winamp Style 3-Window snapped application

假如想象 提交于 2019-12-07 18:50:01
问题 How can I create a Winamp-Style multiple-form snapped application in C# and .net 2.0? 回答1: Easy! Create three forms Add code to custom-draw everything on those three forms Add logic to handle the user clicking and dragging anywhere on any of the forms, such that the window is moved normally until it comes within a certain distance of another one of your own forms (or the edge of the screen), in which case you would snap the window position to that edge. I look forward to your follow-up

C#: XPath to select node with attribute containing a substring?

旧巷老猫 提交于 2019-12-07 13:04:37
问题 Could I use XPath to select country node whose code containing UK? <country-list> <Country code="TW,UK,MY" /> <Country code="US,CA,MX" /> <Country code="IN,PR,VI,IR" /> <Country code="Others" /> </country-list> Thanks. 回答1: Try the contains() XPath function. Something like: /Country[fn:contains(@code, "UK")] A quick Google search turns up details on XPath functions: http://www.w3schools.com/xpath/xpath_functions.asp 回答2: You need write it this way: /country-list/Country[contains(@code,'UK')]