Scott Hanselman

Unions (or an equivalent) in C# - Sairama's Tip of the Day

January 28, 2003 Comment on this post [0] Posted in Web Services
Sponsored By

Someone needed "union" functionality in C# and Sairama came up with this creative and possible heretical use of Interop Attributes.

      [ StructLayout(LayoutKind.Explicit) ]
      public struct UnionTest
      {
      // Set the offsets to the same position so that both variables occupy
      // the same memory address which is essentially C++ union does.

            [ FieldOffset(0) ] public char                  chVal;
 
           [ FieldOffset(0) ] public System.Int16          intVal;
     }     

      class Class1
      {
            [STAThread]
            static void Main(string[] args)
            {
                  UnionTest u = new UnionTest();
                  // Set via Int and get through Char
                  u.intVal = 65;
                  Console.WriteLine("chVal:{0}",u.chVal );
                  // Set via Char and get through Int
                  u.chVal = 'B';
                  Console.WriteLine("intVal:{0}",u.intVal );
            }

Disclaimer
The code above shows only features of .NET and in no way suggest/dictates/advises usage.  Don't be lame and think this is source code you can actually do something with.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

"Energy Consumption" or "Can We Recapture The Extra Heat From My Funeral Pyre?"

January 27, 2003 Comment on this post [0] Posted in Musings
Sponsored By

As a self-declared "Energy Star" person, driving a Toyata Prius currently getting 44 mpg, as well as various other green lifestyle choices, I found myself in a very interesting discussion earlier today as I insulted my co-workers choice of 15 mpg Giant Barns On Wheels.  The suggestion was made that since I had such guilt over causing damage to the environment through my personal use of dead dinosaurs for personal transport that I should perhaps result to self-immolation as a way to atone for my pain.

This left me wondering, how could I recapture and reuse the energy from my funeral pyre for use by my decendants?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Windows 2000 - running for over 2 years, no reboot

January 27, 2003 Comment on this post [0] Posted in Bugs
Sponsored By

Windows 2000 site goes over two years without a reboot

This month is the first time that a Windows 2000 site has appeared in the 50 top sites which have the longest period of time since last reboot. www.byteandswitch.com has been running continuously since November 2000. When we first started graphing web servers uptime in the summer of 2000, many people were skeptical that a Windows machine would ever make the top 50. Perceptions change, and although two years is exceptional, several Windows 2000 sites have run for more than a year without a reboot. In the hosting industry, Microsoft partners Interliant and Divine each have sites that have not been rebooted in over a year, while Microsoft has also run several of its own sites for over a year between reboots. 

Heh...Remember the Windows 9x 49.7 day bug?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Scott's Law of Unit Testing

January 26, 2003 Comment on this post [0] Posted in Web Services
Sponsored By

My dentist said to me, "If you don't floss, then you might as well not bother brushing."

I have ammended this to "If you don't write Unit Tests, then you might as well not bother coding."

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

ALERT! SQL Server Worm - PATCH YOUR SERVERS TO SP3

January 25, 2003 Comment on this post [0] Posted in Web Services
Sponsored By

http://slashdot.org/article.pl?sid=03/01/25/1245206

"Since about midnight EST almost every host on the internet has been receiving a 376 byte UDP payload on port ms-sql-m (1434) from a random infected server. Reports of some hosts receiving 10 per minute or more. internetpulse.net is reporting UUNet and Internap are being hit very hard. This is the cause of major connectivity problems being experienced worldwide. It is believed this worm leverages a vulnerability published in June 2002. Several core routers have taken to blocking port 1434 outright. If you run Microsoft SQL Server, make sure the public internet can't access it. If you manage a gateway, consider dropping UDP packets sent to port 1434." bani adds "This has effectively disabled 5 of the 13 root nameservers."

Installing SQL Server SQL 3 fixes this problem!  It pays to stay up to date (and get up early on a Saturday and walk straight over to your computer...)

Details at the links below:

http://www.sarc.com/avcenter/venc/data/w32.sqlexp.worm.html
http://www.kb.cert.org/vuls/id/370308
http://www.kb.cert.org/vuls/id/399260
http://www.kb.cert.org/vuls/id/484891

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.