|
I need to instatiate a dictionary accepting null as value, but I have a syntax problem:
Dictionary<string, double[]?> d = new Dictionary<string, double[]?>()
d.Add("a", new double[2]{100,102});
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });;
Is it possible to do it?
|
|
|
|
|
What happens when you try?
Use the best guess
|
|
|
|
|
You don't need the '?' at all - you need that to specify a value type that can hold a null value. Reference types automatically can (as this is the default value for a reference type variable)
All arrays are reference types, regardless of whether they are array of reference or value types. So what you need to say is:
Dictionary<string, double[]> d = new Dictionary<string, double[]>();
d.Add("a", new double[2] { 100, 102 });
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });
You would only need the '?' if you wanted an array of doubles that could hold null values, and then the syntax would be:
double?[] da = new double?[10]; To indicate that the individual elements of the array could contain nulls.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Thanks in this way I'm not able to find the Max value of first element
var ks = d.Max(v => v.Value[0]);
I didn't clarify before this port sorry
|
|
|
|
|
Then all you need to do is change the lambda expression to allow for the null value:
var ks = d.Max(v => v.Value == null ? 0.0 : v.Value[0]);
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
thanks in this case I see you need a "hard coded" value 0.0. Is it possible to say "if null just skip it"?
|
|
|
|
|
No, there is no way to "miss out" a value in a IEnumerable iteration.
You could use double.MinValue instead:
var ks = d.Max(v => v.Value == null ? double.MinValue : v.Value[0]);
or
var ks = d.Max(v => { if (v.Value == null) return null; return v.Value[0]; });
But then you need to check for null in the ks variable as a list with all nulls with return a null instead of a double value.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
OriginalGriff wrote: No, there is no way to "miss out" a value in a IEnumerable iteration. Ahem![^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hadn't thought of Where - good point!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
You can use the Where method[^] to skip the null items:
var ks = d.Where(v => v.Value != null).Max(v => v.Value[0]);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
use like this
Dictionary<string, Nullable<double>[]> d = new Dictionary<string, Nullable<double>[]>();
d.Add("a", new Nullable<double>[2] { 100, 102 });
d.Add("b", null);
d.Add("v", new Nullable<double>[2] { 99, 101 }); ;
It would help you.
|
|
|
|
|
I am revisiting a project that I have wanted to do for a long time. I am trying to read Minidumps much like BlueScreenView just with C# code. I was pointed to using
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern bool MiniDumpReadDumpStream(IntPtr BaseOfDump,
int StreamNumber,
ref MINIDUMP_DIRECTORY Dir,
ref IntPtr StreamPointer,
ref UInt32 StreamSize);
And after much digging, I found this
http://www.symbolsource.org/Public/Metadata/NuGet/Project/Microsoft.Samples.Debugging.CorApi/1.4.0.0/Release/Default/Microsoft.Samples.Debugging.Native/Microsoft.Samples.Debugging.Native/DumpReader.cs[ ]
But I am having an issue with being able to pass in a string to the DumpReader and then read the return value. It appears that I need to pass a targetaddress and the length to the ReadMemory but I am getting an exception. I am very new to the whole native code thing. I like my .Net Libraries.
From DumpReader.CS
public byte[] ReadMemory(ulong targetAddress, int length)
{
byte[] buffer = new byte[length];
ReadMemory(targetAddress, buffer);
return buffer;
}
From My Code:
DumpReader dr = new DumpReader(PathToDump);
dr.ReadMemory(??, ??);
|
|
|
|
|
There's an easier example here[^]. I've got it working using the 4.0 runtime, seems the VS-IDE doesn't read them that well for the 2.0 runtime.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I see that the link in your post describes how to create a MiniDump but what I am looking to be able to do is read them. I am not interested in reading them in VS but through code like BlueScreenView
|
|
|
|
|
Zach.Saunders wrote: I am not interested in reading them in VS but through code like BlueScreenView
And yet you ask the question in a C# forum!
What do you mean by code like BlueScreenView.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I would like to be able to open up the .dmp files programmatically in a C# application and read the output to a form. I am trying to literally make a program that behaves just like Nirsoft's BlueScreenView.
|
|
|
|
|
Zach.Saunders wrote: I would like to be able to open up the .dmp files programmatically in a C# application and read the output to a form. Here's[^] the file format for a Windows CE 5 structure to give an idea how it looks. I don't know where the one for Windows 7/8 is, or even if it's publicly available.
You'd have to research that
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I noticed within the past week or two my latest builds of a specific project are not showing up in Add/Remove programs.
I am using Visual Studio 2010, Windows 7 64 bit (though I've also tried 2 32 bit machines). All latest service packs and updates are installed. The solution is made up of several projects with various references. The Setup and Deployment project is not the Install Shield version, but the built in Microsoft project.
Previous versions of the software installed fine, and still do... but if I pull down a tagged earlier version from CVS, and rebuild the installer for those versions, they do not work either.
I've opened the MSI in Orca, and I can see that the ARPNOREMOVE, ARPSYSTEMCOMPONENT are both set to 1. When the project gets installed, a registry entry SystemComponent Dword value is created. If I remove that registry entry, the application shows up. Based on everything I've read and researched I have found people that WANTED this funcitonality but were told Visual Studio can not do this on its own and their solutions were to use Orca to add the ARPNOREMOVE or ARPSYSTEMCOMPONENT. At this point, all of the people who had my problem that I can find either had a basic default installer and they didn't know what name they were looking for in Add/Remove Programs or some other basic error that doesn't apply in my situation.
I've tried all of the following.
-Previous versions of tagged versions on CVS
-Multiple development machines
-Multiple computers to verify none show up in Add/Remove programs -Resetting all Visual Studio settings
-Building from a clean development environment
-Removing Installer project from the solution and creating a new installer project
The weird part is that if I create a new solution and just create a setup and deployment project within, that installs fine.
|
|
|
|
|
Since I'm in desperate mode, I wrote a post build event to modify the installer... all it is doing is removing the entry 'ARPSYSTEMCOMPONENT'. I suppose I'll also need to the do the same with the ARPNOREMOVE, and the others...
Surely I'm not the first person this has happened to.
|
|
|
|
|
So this is what I found out. We are using National Instruments Measurement Studio for .Net and the legacy controls. When using the legacy controls a certain merge module gets recognized as a dependency. For whatever reason, now this merge module change the behavior of the installer that is compiled. I've contacted National Instruments and am now working with them.
|
|
|
|
|
I create MemoryMappedFile like this :
mmf = MemoryMappedFile.CreateFromFile(filename, FileMode.OpenOrCreate, name, length, MemoryMappedFileAccess.ReadWrite);
but after use if i try to remove file from disk it is "in use" :
mmf.Dispose();
mmf = null;
File.Delete(filename); // cause exception
how i can remove it without end of application ? All reader/writer are disposed too.
|
|
|
|
|
have you tried using Finalize() instead of Dispose() ? (just wondering if that would make a difference)
your
mmf = ... line is probably better served wrapped in a 'using' block btw
'g'
|
|
|
|
|
mff has no Finalize() member
and all MemoryMappedViewAccessor's are wrapped into 'using' blocks, but mmf is "global" and will be accessed from different parts of code.
|
|
|
|
|
What's the best way to notify the front end of a business rule or possible FK violation? For example, I have a lookup called PayType, and so far my DeletePayType looks like this:
public static void DeletePayType(int PayTypeId)
{
using (var dc = getDataContext())
{
bool inUse = isPayTypeInUse(PayTypeId);
if (inUse)
{
throw new Exception("Pay Type is in use and cannot be deleted");
}
else
{
var payType = (from ca in dc.PayTypes
where ca.PayTypeId == PayTypeId
select ca).FirstOrDefault();
if (payType != null)
{
dc.PayTypes.DeleteOnSubmit(payType);
try
{
dc.SubmitChanges();
}
catch (Exception e)
{
throw e;
}
}
}
}
}
Throwing an exception doesn't seem right, but I need the client to know that the pay type is in use and can't be deleted.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Yup programming by error - try and delete the record and then inform the user when it fails - start looking for some other employment.
Here is one reason I ALWAYS use a stored proc, the delete procedure check the FK table and only deletes the record if there is no constraint.
Never underestimate the power of human stupidity
RAH
|
|
|
|