Solved

C# -- what is "strongly-typed" ?

Posted on 2009-07-10
4
730 Views
Last Modified: 2012-05-07
What does "strongly-typed" mean ?
0
Comment
Question by:finance_teacher
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24827685
it means that this is not allowed by the compiler:
string x = 1; 
while this works:
string x = "1";

Open in new window

0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24827882
angelIII is correct because in line 1, the value 1 is an integer not a string (the expected data type).
string x = "Hello";

x = "World";

x = 0.00; <-- This line would fail because 0.00 is a double.
 

However,
 

if you do:

x = 0.00.ToString(); <-- This line would work because the value is converted to a string first.

Open in new window

0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 24828227
Well, I think of strongly-typed as being "intellisenseable". A DataTable that is strongly typed can have its fields named instead of indexed (dt.Rows.FirstName instead of dt.Rows["FirstName"]). Also, you can have a typo in the last case but not in the first case (without getting a compile error).
Gary Davis
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24833047
I think of "strongly typed" as opposed to loosely typed.

Strong typing is often used in the same context as static typing. It means the compiler guarantees, through a strong type system, and compile time checking, that a variable will not be used at runtime in some unknown / unsupported way. You can guarantee not to have a runtime type conversion error or exception.

This differs from languages like Perl and Ruby where a type goes with the value, and depending on the value in a variable at any given time, the operations and conversions no that variable may change.

Languages like Perl do not even allow you to specifically create a typed variable (or not easily) but they are all treated as scalars or variants.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now