Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does strongly typed means in .NET framework?

Tags:

This morning was going through a book where I found a paragraph as stated below :

Each data field in a table is a strongly typed data member, fully compliant with .NET’s Common Type System.

Does the above lines means " that objects written in different languages can interact with each other like "

And if it means the above lines what does exactly the above line means by saying different languages can interact with each other like

I am trying to work out with an example but no success till now.

Or is it something that i am missing and need to know. Please help me to understand.

Thanks in advance

like image 450
Tony Avatar asked May 28 '12 05:05

Tony


People also ask

What is meant by strongly typed in C#?

The C# language is a strongly typed language: this means that any attempt to pass a wrong kind of parameter as an argument, or to assign a value to a variable that is not implicitly convertible, will generate a compilation error. This avoids many errors that only happen at runtime in other languages.

What does strongly typed mean?

What Does Strongly Typed Mean? Strongly typed is a concept used to refer to a programming language that enforces strict restrictions on intermixing of values with differing data types. When such restrictions are violated and error (exception) occurs.

What is strongly typed and weakly typed in C#?

"Weakly typed" means "this language uses a type verification system that I find distasteful", and "strongly typed" means "this language uses a type system that I find attractive".

What is the difference between strongly typed and weakly typed?

Strongly typed means, a variable will not be automatically converted from one type to another. Weakly typed is the opposite: Perl can use a string like "123" in a numeric context, by automatically converting it into the int 123 . A strongly typed language like python will not do this.


Video Answer


2 Answers

For e.g you cannot Multiply or Divide two different types i.e String vs Integer

var answer = 1 * "1"; // you cannot do this 

You have to explicity cast it, this is known as strongly typed

where as if you see in php

$x = "3" * 1; // is correct in php 

So here you dont need to explicitly cast it.

like image 156
FosterZ Avatar answered Oct 22 '22 14:10

FosterZ


When we say something is strongly typed we mean that the type of the object is known and available.

Let say I have a function like following

public int Add(int a, int b){  return a+b; } 

We can call this function like

int result = Add(5,4); 

But we can not do like following

int result = Add(5.2,4.5); // We will get here compilation error. 

C# (and C++ and many other languages) is strongly typed because the compiler will detect and flag these errors at compilation time.

See here

like image 23
Atish Dipongkor Avatar answered Oct 22 '22 14:10

Atish Dipongkor