Click here to Skip to main content
16,016,795 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
what is the role of mscorlib in dotNET?? how it is different from other libraries?
Posted

In essence mscorlib isn't different from the other libraries in .NET. But it is the base of .NET and doesn't depend on any other assembly, but all the other assemblies in the .NET framework depends on mscorlib.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Sep-11 0:17am    
Basically, correct, my 5, but there is at least one special aspect of it.
Please see my solution; your answer is credited.
--SA
Have a look at This[^]

hope it helps :)
 
Share this answer
 
Comments
Harmanjeet Singh 11-Sep-11 16:19pm    
nice link. thanx :)
Uday P.Singh 11-Sep-11 23:37pm    
welcome :)
I want to contribute to a correct answer by Simon.

Not only other assemblies depend on mscorlib; there is something else which always uses this library. In particular, this is C# language.

You can always avoid explicit use of any libraries at all. You can create a class library not using System namespace. For example, it could implement some pure numerical or string manipulation algorithms from scratch and export them in the form of public classes/structures and methods. (Why just the library? Yes, it can be even an application, but quite useless one as it could not output anything without the libraries.)

Will it use mscorlib? It will, because you need to use at least embedded types like int, uint, double, string and the like. Yes, all these identifiers are keywords of the language, but they are implemented as the aliases of System.Int32, System.UInt32, System.Double and System.String, respectively.

[EDIT]

Thanks to Simon for bringing the issue of dependency of all the types upon System.Object. This problem is not that simple. Consider the following:

C#
int value = 13; //still, has nothing to do with System.Object. This is a primitive type using exactly 32 bits

System.Console.WriteLine("Value={0}", value); //value is boxed to a type derived from System.Object

//Why? because the signature of WriteLine is
static void WriteLine(string format, params object[] parameters); //accepts System.Object
//so primitive types are subject to boxing


See http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Simon Bang Terkildsen 12-Sep-11 0:35am    
+5 I didn't consider that.
I just what to add Object you cannot avoid using, as any class that does not inherit another class implicitly inherits Object.
Sergey Alexandrovich Kryukov 12-Sep-11 0:47am    
Thank you, Simon.

With object, this is not that simple though. Does the type like System.Int32 inherit from System.Object or not? Yes and no. It this is the primitive-type int, it does not. If it is a boxed form of it, it does.

--SA
Sergey Alexandrovich Kryukov 12-Sep-11 0:55am    
...so, I added the update to my solution explaining this, after [EDIT], please see.
--SA
Simon Bang Terkildsen 12-Sep-11 1:06am    
As always you're one step ahead of me (or two :) )
I didn't consider boxing, only that class MyClass implicitly inherit from Object, so unless your class library doesn't have a class, then Object is inherited.
Sergey Alexandrovich Kryukov 12-Sep-11 1:10am    
Correct. Or using some library class which would require explicit use of mscorlib as well.
--SA

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