Solved

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

The purpose of this article is to demonstrate how we can use conditional statements using Python.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

809 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