Solved

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

Posted on 2009-07-10
4
744 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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

26 Experts available now in Live!

Get 1:1 Help Now