Solved

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

Posted on 2009-07-10
4
772 Views
Last Modified: 2012-05-07
What does "strongly-typed" mean ?
0
Comment
Question by:finance_teacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

724 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