Posted by blockwood on 6/8/2010 6:58 AM | Comments (0)
First, there is the implicit cast. This is the cast that doesn't
require you to do anything more than an assignment:

int i = 5;
double d = i;

These are also called "widening conversions" and .NET allows you to
perform them without any cast operator because you could never lose any
information doing it: the possible range of valid values of a double
encompasses the range of valid values for an int and then some, so
you're never going to do this assignment and then discover to your
horror that the runtime dropped a few digits off your int value. For
reference types, the rule behind an implicit cast is that the cast
could never throw an InvalidCastException: it is clear to the compiler
that the cast is always valid.

You can make new implicit cast operators for your own types (which
means that you can make implicit casts that break all of the rules, if
you're stupid about it). The basic rule of thumb is that an implicit
cast can never include the possibility of losing information in the
transition.

Note that the underlying representation _did_ change in this
conversion: a double is represented completely differently from an int.

The second kind of conversion is an explicit cast. An explicit cast is
required wherever there is the possibility of losing information, or
there is a possibility that the cast might not be valid and thus throw
an InvalidCastException:

double d = 1.5;
int i = (int)d;

Here you are obviously going to lose information: i will be 1 after the
cast, so the 0.5 gets lost. This is also known as a "narrowing"
conversion, and the compiler requires that you include an explicit cast
(int) to indicate that yes, you know that information may be lost, but
you don't care.

Similarly, with reference types the compiler requires explicit casts in
situations in which the cast may not be valid at run time, as a signal
that yes, you know there's a risk, but you know what you're doing.

The third kind of conversion is one that involves such a radical change
in representation that the designers didn't provide even an explicit
cast: they make you call a method in order to do the conversion:

string s = "15";
int i = Convert.ToInt32(s);

Note that there is nothing that absolutely requires a method call here.
Implicit and explicit casts are method calls too (that's how you make
your own). The designers could quite easily have created an explicit
cast operator that converted a string to an int. The requirement that
you call a method is a stylistic choice rather than a fundamental
requirement of the language.

The stylistic reasoning goes something like this: String-to-int is a
complicated conversion with lots of opportunity for things going
horribly wrong:

string s = "The quick brown fox";
int i = Convert.ToInt32(s);

As such, the method call gives you documentation to read, and a broad
hint that this is something more than just a quick cast.

When designing your own types (particularly your own value types), you
may decide to create cast operators and conversion functions. The lines
dividing "implicit cast", "explicit cast", and "conversion function"
territory are a bit blurry, so different people may make different
decisions as to what should be what. Just try to keep in mind
information loss, and potential for exceptions and invalid data, and
that should help you decide.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 6/7/2010 6:46 AM | Comments (0)

Here are the demos and experiments I walked through during class.  Feel free to download these and use as a guide for your own development.

Chapter 01 ".NET What you need to know"- Chapter 1.zip (80.31 kb)

Chapter 02 "First C# Programs" - Chapter 2.zip (37.74 kb)

Chapter 03 "Data Types in C#" - Chapter 3.zip (44.80 kb)

Chapter 04 "Operators & Expressions' - Chapter 4.zip (22.37 kb)

 

If you're switching over to VS 2010, here is a cool set of tools.  http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef

Currently rated 2.0 by 1 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 5/26/2010 1:14 AM | Comments (0)

WorkingwithASPNET_SilverlightHTML.zip (59.53 kb)

 

Example of the Silverlight 3 Toolkit using the Bar Series

 

BenchmarkSampleOfToolkit3Csharp.zip (1.62 mb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 5/24/2010 12:35 AM | Comments (0)

If you installed the latest version of Silverlight (Silverlight 4), it may break the your current silverlight development environment. After the Silverlight 4 installation, if you try to debug any Silverlight 3 project, you will get this message from Visual Studio 2008, saying “Unable to start debugging. The Silverlight managed debugging package isn’t installed.”

Unable to start debugging. The Silverlight managed debugging package isn't installed.

Unable to start debugging. The Silverlight managed debugging package isn't installed.

To fix this error, install the Silverlight Developer Run time. You can get it from here : http://go.microsoft.com/fwlink/?LinkID=188039.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Posted by blockwood on 5/21/2010 7:21 AM | Comments (0)
http://learning.microsoft.com/manager/LearningPlanV2.aspx?resourceId=793d0564-7eee-44e0-8f70-cd31748ac3b0&clang=en-US&cats=d4e8e42c-3d5a-4a6e-915d-d99556a49bd7

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Posted by blockwood on 5/21/2010 7:11 AM | Comments (0)

Created via http://www.wordle.net

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 5/14/2010 5:09 AM | Comments (0)

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , | Posted by blockwood on 5/7/2010 2:36 AM | Comments (0)

Yesterday was an incredible day.  I was one of the speakers at TechFuse (www.benchmarklearning.com/techfuse.aspx) .  My three sessions were:

  1. We're Scientists - Effective prototyping is imperitive
  2. .NET Basket Weaving - WCF, WPF, WF, Silverlight & LINQ
  3. Jump, Step, Juke your way in your career

The solution for the .NET Basket Weaving solution can be downloaded here:

VB.NET: CareerServicesVB.zip (458.02 kb)

C#.NET: CareerServices.zip (321.02 kb)

Even though there were "curve balls" (literally someone threw a baseball, thanks Tim), believe it or not there was a standing ovation!  What a fun day! 

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 5/5/2010 1:42 AM | Comments (0)

How Message and Transport Security Compare

Pros and Cons of Transport-Level Security

Transport security has the following advantages:

  • Does not require that the communicating parties understand XML-level security concepts. This can improve the interoperability, for example, when HTTPS is used to secure the communication.
  • Generally improved performance.
  • Hardware accelerators are available.
  • Streaming is possible.

Transport security has the following disadvantages:

  • Hop-to-hop only.
  • Limited and inextensible set of credentials.
  • Transport-dependent.

Disadvantages of Message-Level Security

Message security has the following disadvantages:

  • Performance
  • Cannot use message streaming.
  • Requires implementation of XML-level security mechanisms and support for WS-Security specification. This might affect the interoperability.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Posted by blockwood on 5/5/2010 1:39 AM | Comments (0)

StackOverflow Comment: 

Combining WCF with WF (Workflow Foundation) seems like the best option here. Workflow Foundation gives you lots of goodies, including long-term persistence over the lifetime of your long-running process.

In .NET 3.5, it's possible to do so, but clumsy and a lot of work.

Here are a few links for this topic:

With .NET 4.0, these "WorkflowServices" will be a big part of the new WF/WCF 4.0 package. You should basically be able to expose an interface for any workflow as a WCF service. Sounds very promising, haven't had a chance to try it myself.

Some links for the new stuff:

Another great article can be found here: http://www.west-wind.com/WebLog/posts/67557.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5