C#’s HashSets

One thing that you encounter whenever you interview for a position as a .NET developer the technical question. That can make many forms, such as the famous “fizz-buzz” puzzle. But one that has always stumped me is how to find common elements between two arrays of the same data type. I’ve always come up with using two loops, one within another, which is of type O(n2). In the .NET framework I’ve recently learned of HashSets, which are extremely cool. This makes finding common elements easy. To learn more about them I decided to write a simple console app to try it out. This is based upon the MSDN online article on HashSets, which I’ve expanded upon. Here’s the source code:

using System;
using System.Collections.Generic;
using System.Linq;
namespace SimpleHashSet
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Learning about HashSets\r\n\r\n");
HashSet<int> setA = new HashSet<int>();
HashSet<int> setB = new HashSet<int>();
for (int i = 0; i < 5; i++)
{
setA.Add(i * 2);
setB.Add(i * 2 + 1);
}
//now, just add 100 to both
setA.Add(100);
setB.Add(100);
Console.WriteLine("setA contains {0} elements:", setA.Count);
DisplaySet(setA);
Console.WriteLine("setB containts {0} elements:", setB.Count);
DisplaySet(setB);
Console.WriteLine();
//what is the intersection?
HashSet<int> theIntersection = new HashSet<int>(setA);
theIntersection.Intersect(setB);
Console.WriteLine("Using the Intersect method on setA with setB");
DisplaySet(theIntersection);
Console.WriteLine();
//what is the intersecion with about?
HashSet<int> intersectWith = new HashSet<int>(setA);
intersectWith.IntersectWith(setB);
Console.WriteLine("Using the IntersectWith method on setA with setB");
DisplaySet(intersectWith);
Console.WriteLine();
//what about the union method?
HashSet<int> theUnion = new HashSet<int>(setA);
theUnion.Union(setB);
Console.WriteLine("Using the Union method on setA with setB");
DisplaySet(theUnion);
Console.WriteLine();
//what about the UnionWith method?
HashSet<int> unionWith = new HashSet<int>(setA);
unionWith.UnionWith(setB);
Console.WriteLine("Using the UnionWith method on setA with setB");
DisplaySet(unionWith);
Console.WriteLine();
//what is the Except method all about?
HashSet<int> theException = new HashSet<int>(setA);
theException.Except(setB);
Console.WriteLine("Using the Except method on setA with setB");
DisplaySet(theException);
Console.WriteLine();
//now try the ExceptWith method
HashSet<int> exceptWith = new HashSet<int>(setA);
exceptWith.ExceptWith(setB);
Console.WriteLine("Using the ExceptWith method on setA with setB");
DisplaySet(exceptWith);
//this is the end
Console.WriteLine("\r\n\r\nPress any key to quit.");
Console.ReadKey();
}
private static void DisplaySet(HashSet<int> passedSet)
{
Console.Write("{");
foreach (var item in passedSet)
{
Console.Write(" {0}", item);
}
Console.WriteLine(" }");
}
}
}
If you run the preceding code you’ll get this in the command window:
2016-03-11
Don’t know about you, but I find things like this handy to use a refer back to.

I’m finally giving up trying to upgrade to Windows 10

I have Windows 10 installed on some desktops and laptops. It’s gone well, until I tried it on my 3 year old Sony VAIO. Initially I got an email from Sony strongly suggesting that I not upgrade my VAIO until they had made necessary changes to the device drivers. I waited until they told me that they were ready. Some months ago I got a follow-up email from Sony informing me that they had fixed their device drivers so that I could upgrade my Sony VAIO. So I started trying to update my Sony VAIO.

That was about 3 months ago. Over that period of time I’ve made at least 11 attempts to update from Windows 8.1 Professional to Windows 10 Professional on my Sony VAIO. I tried the update wizard 5 or 6 times. All failed.

I tried another method (can’t remember exactly what it was called, but it’s the next method after trying the general Windows 10 Update Wizard). I tried that 4 or 5 times, and that failed each time.

Finally I was advised to go to a Microsoft website to download the .ISO file and run the setup from that. I did that and man, did that ever fail badly. I had no access to my keyboard or mouse. It took me days to finally get the keyboard and mouse working again so that I could back out the Windows 10 upgrade.

11 failed attempts to update my 3 year old Sony VAIO.

Sony, I don’t know if you’ll read this or not. I hope you do. Please, when you send out emails to your customers telling them that you’ve fixed your device drivers DO A BETTER JOB OF TESTING!!

To anyone else who reads this who owns a Sony VAIO that’s 3 or 4 years old. Trust me, don’t try to upgrade to Windows 10. The machine won’t accept Windows 10 at all. I use Windows 10 on other systems, it works fine. Sony just haven’t done the job they said they were going to do to update their device drivers to allow the update to Windows 10. Save yourself the aggravation, don’t make the attempt. Instead save up some money and get some other machine that will allow you to upgrade or is already at Windows 10.

Yet another failed attempt at upgrading to Windows 10

Tonight I had the time to try upgrading from Windows 8.1 Professional to Windows 10 Professional again. I think this is my 11th attempt to upgrade to Windows 10 (I’ve honestly lost count). And tonight I downloaded the .ISO file and run the setup from within it. It did get past the place where it was hanging before. So I thought I was out of the woods, finally.

In that I was deceived, because when it was trying to finalize things and let me log in, I got the following error:

“KERNEL SECURITY CHECK FAILURE”

now the keyboard doesn’t work, it refuses to connect to my Wi-Fi network and basically I’ve now got a nearly useless laptop. I’m not even sure I can get it back to Windows 8.1 Pro anymore, if I cannot use the keyboard. I cannot even power it down or log it off because its refusing to work. Pretty bad.

My upgrade to Windows 10 continues to encounter problems

I continue to encounter problems trying to upgrade my Sony VAIO from Windows 8.1 Pro to Windows 10 Pro. I called Microsoft technical support to get more help. They wanted me to try the regular update routine. However I suspect that the issue is still with Sony, who suggested that I upgrade to Windows 10 first before upgrading the device drivers. Next I get the error. See the picture attached.

Posted from WordPress for Windows Phone

Having major problems upgrading my laptop

As I recently posted I have a Sony VAIO laptop. I tried some time ago to upgrade it. Sony sent me an email a couple of weeks ago saying that they’re ready. What I’m supposed to do is upgrade to Windows 10 Pro (I’ve currently got Windows 8.1 Pro) and then get the updated device drivers.

Well I started that process 2 days ago. It got to 97% done (88% finished configuring). And there it sat for 2 days (I was afraid to do more).

Microsoft’s Windows Support on Twitter has said that I’ve got to shut down the machine and try to recover.

Will keep you all posted…

Thankfulness

I’m thankful to be employed

Today is Thanksgiving Day 2015. Normally I don’t post about daily things, as I tend to keep this blog for technical posts in nature, but I felt that I had to post something that I’m thankful for this year. In short, I’m thankful for my job.

Such a change a year can make

Last year was a very hard year for my family and I. After working for several years at my previous job, I was one of those laid off in 2014 due to on going budgetary cutbacks. My previous employer had been experiencing cutbacks in budget each year since 2008. This resulted in layoffs each year due to those cutbacks.  According to Wikipedia the Great Recession ended in 2009. But it isn’t exactly like everything turns rosy and suddenly industry is operating at 200% of its previous efficiency and productivity. Certain places lag behind others, sometimes by years. Where we live, we lag by a lot.

2014 for us was very hard. Thanksgiving 2014 for us was humble. We weren’t sure when I was going to get a new job. When you’re unemployed for a while each purchase is a trade off between do we eat something or save money for a job search. You cut what you can, to help make something else you need come about. Or at least you hope. It took longer, but it finally came.

 This year is better

This year is better. This year I have a new job. We can buy our own turkey. We’re not worried as we were a year ago. In this day and age Thanksgiving tends to be a forgotten holiday, offering little more than food, football and fast purchasing in preparation for Christmas. But for me it is a time to reflect. I think back to last Thanksgiving and compare it to this Thanksgiving. I thank God for my new job.

Thanksgiving Painting.png