Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
The C# built-in types web page only listed the bottom types as built-in Value types and built-in Reference tyes. But aren't the succeeding types Timer, Math, IComparable, File so on and so forth also built-in types? Since they too were provided by the Microsoft team for any developer to use.

The following table lists the C# built-in value types:

- bool
- byte
- sbyte
- char
- decimal
- double
- float
- int
- uint
- nint
- nuint
- long
- ulong
- short
- ushort

The following table lists the C# built-in reference types:

- object
- string
- dynamic

What I have tried:

How to diffentiate between built-in and non built-in types
Visual studio
Posted
Updated 16-Aug-21 9:01am
Comments
[no name] 15-Aug-21 15:42pm    
Timer, etc, are "classes" in the ".NET framework library"; which for all intents is an "add on"; derived from the "built-in" types; to aid in development; so you don't have to build them.
Matildemona 15-Aug-21 15:59pm    
A colleague of mine (we're both new to C#) advised me that built-in types are types that are natively in the C# language (no need to import any namespace to use them) while other types provided by Microsoft are not built-in types since a namespace needs to be imported in order to use those types in code. As that true?
PIEBALDconsult 15-Aug-21 17:16pm    
No namespace ever needs to be "imported" in C#.
Do you mean add a reference to a different DLL?
Matildemona 15-Aug-21 17:53pm    
No, I did I mean importing a namespace. Because isn't the using directive meant for importing a namespace into a source code file in c#?
PIEBALDconsult 15-Aug-21 20:50pm    
Which is never necessary in order to use the types defined within it.

And of course it does nothing to the source code file.

No, built in types are the "basic building blocks" of the language (or strictly speaking, the Framework) and do not require any special treatment or using statements:
C#
public class Program
    {
	public static void Main()
    	{
    	int x = 95;
    	int y = 3;
    	string str = ((double) x / (double) y).ToString("F2");
        }
    }
Will compile and run (though it will not be in any way useful ...)
Everything else needs something to say what Namespace it comes from: even somethign as simple as adding
C#
Console.WriteLine(str);
To make it do anything even vaguely useful requires the System namespace, normally via
C#
using Sytem;
At the top of the file.
The File class needs System.IO for example, and so on, and so on.

Basically, if its isn't on the "built in list", it's a framework (or external) addon!
 
Share this answer
 
Comments
Matildemona 15-Aug-21 16:36pm    
A colleague of mine advised me with something similar "built-in types are types that are natively in the C# language (no need to import any namespace in order to use them) while other types provided by Microsoft are not built-in types since a namespace needs to be imported in order to use those types in code." Is that fundementally the same as what you said?
OriginalGriff 15-Aug-21 16:53pm    
That gets a bit ... grey area ...
Are they "native to C#"? Or "native to the .NET framework"? Bear in mind that the same list applies to VB as well, but that the C# keywords are names which are interchangeable with teh .NET versions on which they depend.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types

I'd hesitate to say either they are or they aren't "built in to C#" since C# the language and .NET the framework are pretty much inseparable! :laugh:
Matildemona 15-Aug-21 17:22pm    
Just to be on the safe side. I'll just jot down that built-in types are native to C# / .net framework :laugh:

But i'm curious, if those types I mentioned to aren't called built-in types then what are they called? (e.g. types that you or I create, per say, are called user-defined types).
PIEBALDconsult 15-Aug-21 17:26pm    
Right, no types are actually built into the language, they're all part of the Framework / Base Class Library.
But some .net types have aliases to make the most common types easier to reference.
Otherwise, a developer can define his own aliases with a directive such as [ using datetime=System.DateTime ; ] , which is essentially all the types [ int , decimal , string , etc. ] are.
Matildemona 15-Aug-21 18:33pm    
Are you saying that built-in types are built into the .net framework and not built into the C# language?
There is this list:
Built-in types - C# reference | Microsoft Docs[^]
but I still don't think the term "built-in" is quite the right term here.

"is an alias for the corresponding .NET type"

The .net framework has many types "built in", but the C# and VB languages do not.
At most I'd agree that there are a few type aliases upon which a few language elements depend -- such as when defining an enumerated type.

"System-provided type aliases" might be a more accurate term.

Other than that, perhaps you are looking for a list of which types are in System.dll or mscorlib.dll ?
 
Share this answer
 
v2
Comments
Matildemona 15-Aug-21 21:11pm    
yes I agree built-in types could have been better explained, nevertheless, i'm bewildered as to what is actually built into the C# language and what is built into the .Net framework. I have been examining the use between int and Int32 in Visual Studio. While int requires no namespace to be imported in order to be utilized, using Int32 requires the importation of the System namespace. Does this mean aliases (e.g. int) are built into the C# language while the types themseleves (e.g. System.Int32) are built into the .Net framework (specifically in the .net class library)?
PIEBALDconsult 15-Aug-21 23:53pm    
"using Int32 requires the importation of the System namespace" -- No, it does not.

int is simply an _alias_ for System.Int32 , the type _is_not_ built into the language.
Matildemona 16-Aug-21 0:00am    
My mistake. Thank you for correcting me. But I will say it is clear to me now that a "built-in type" is an "alias" (eg. int, char, object, string) to a type (eg. Int32, Char, Object, String) defined in the System namespace.

And how Dave Kreskowiak stated "the 'aliases' to the types defined in the System namespace are built into the C# langauge". Thus, "built-in types" are built into the C# language. While the types themselves, the aliases correspond to, are built into the .Net Framework.

Would you say that is accurate?
PIEBALDconsult 16-Aug-21 0:04am    
Closer to accurate, but I still think it's imprecise.
Matildemona 16-Aug-21 0:14am    
Hopefully you have not lost interest in this post as I am well aware this has been dragging on. But what about the above is imprecise?

Having watched many video tutorials, anaylzing the documentations recommended, along with consideration to all the comments and solutions made in this post that was the conclusion I reached. But I am open for any corrections.
I think you'll find this diagram useful: [^]. From this article: [^].

Of course, you will also want to consider what the current MS "official" classification is: [^].

NameSpaces are a taxonomy: they organize/classify/group different collections of functionality and data, and, you can create your own to control semantic scope, or organize your own work.

With your (deeper) level of interest in the C# language and .NET, let me recommend a book by the language creators: [^]

The C# Programming Language (Covering C# 4.0), Fourth Edition
by Anders Hejlsberg (Author), Mads Torgersen (Author), Scott Wiltamuth (Author), Peter Golde (Author)
2010 Addison-Wesley Professional
ISBN: 9780132484718

This remarkable book includes annotations by some of the most brilliant C# programmers; many of them played a role in creating/evolving C# and .NET: Brad Abrams, Joseph Albahari, Krzysztof Cwalina, Jesse Liberty, Eric Lippert, Christian Nagel, Vladimir Reshetnikov, Marek Safar, Chris Sells, Peter Sestoft, Jon Skeet, and Bill Wagner.
 
Share this answer
 
Comments
Matildemona 16-Aug-21 0:07am    
Thanks. I will make sure to check out that book. I was also recommended C# 8.0 in a nutshell by O'Reilly.
Another potential answer:

"
C# provides a set of predefined struct types called the simple types. The simple types are identified through reserved words, but these reserved words are simply aliases for predefined struct types in the System namespace, as described in the table below.
" -- Types - C# language specification | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900