Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

namespaces: using System & using System.IO [duplicate]

Tags:

namespaces

c#

so my program has these 2 lines at the beginning

using System;
using System.IO;

Question: Is the second statement actually necessary to include Sytem.IO methods and properties in my code? It seems that 'System.IO' is a 'child' of the namespace 'System'. Shouldn't the first line grab all the child namespaces too? Or Do I not understand namespaces correctly?

like image 737
Logan Bender Avatar asked Mar 21 '23 06:03

Logan Bender


1 Answers

System.IO namespace is used for Input Output operations.(Ex: File Operations)

System namespace does not include all child namespaces.
So if you want to perform IO Operations you should include System.IO namespace explicitly.

First Question : Is the second statement actually necessary to include Sytem.IO methods and properties in my code?

Yes it is Necessary as System namespace does not include Child namespaces.

Second Question : It seems that 'System.IO' is a 'child' of the namespace 'System'.

Yes System.IO is a Child of System namespace.

Note : though System.IO is a child namspace of System, it will not be included when you include System namspace

Third Question : Shouldn't the first line grab all the child namespaces too? Or Do I not understand namespaces correctly?

No first line using System; does not grab all the Child namespaces as it is not java to import all child namspeaces using wild card character star *

like image 51
Sudhakar Tillapudi Avatar answered Apr 01 '23 17:04

Sudhakar Tillapudi