how can we write large source code in 2 or more seperate units?
-
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
-
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
That's what
partial
classes are for. -
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
Hi, MSDN is the best platform to start for novice, Check This link for partial class thanks -Amit.
-
That's what
partial
classes are for. -
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
-
I think he is not talking about breaking classes into multiple files, rather it is about breaking the logic into multiple classes and packaging them into libraries.
You may be right. I may need coffee.
-
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
they're called "assemblies" in .Net. Just create a class library project in your solution, and start adding classes to it. To use the classes in that library, you have to include htis line at the top of your file:
using MyLibraryNameSpace;
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
they're called "assemblies" in .Net. Just create a class library project in your solution, and start adding classes to it. To use the classes in that library, you have to include htis line at the top of your file:
using MyLibraryNameSpace;
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997John Simmons / outlaw programmer wrote:
you have to include htis line
No you don't, but he will need a reference.
-
John Simmons / outlaw programmer wrote:
you have to include htis line
No you don't, but he will need a reference.
-
PIEBALDconsult wrote:
No you don't, but he will need a reference.
Actually, both a reference to the asembly and the
using
statment.Shameel wrote:
the
using
statmentIs not required and only weak developers use them.
-
Shameel wrote:
the
using
statmentIs not required and only weak developers use them.
PIEBALDconsult wrote:
not required
Technically, yes. But this code
using Com.Company.Suite.Product.Version.Module;
MyClass c1 = new MyClass();
is more readable by an order of magnitude than this code
Com.Company.Suite.Product.Version.Module.MyClass c1 = new Com.Company.Suite.Product.Version.Module.MyClass();
-
when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx
I think another way to "frame" this question ... if my intuition is on-line here ... is to ask: how can I design, or re-design, my getting-very-big project into functional units, or: how can I determine a set of "organic criteria" which to use as an "organizing principle" to divide my project into logical "chunks" which, in the long run, contribute to program extension, maintenance, and de-bugging (and lend themselves to unit-testing in "isolation" ?). All the "tools" mentioned here, including "Partial Classes," "Class Libraries," etc. are valuable. ... edit in appreciative response to feedback from PiebaldConsult ... Please note: in Visual Studio the option to create a "Class Library" is one that appears when you create a new Solution, and also appears as an option when you choose to add a "New Project" to an existing "Solution." The question of whether a "Solution," which "begins life" as "only" a "Class Library," is, semantically, a "Solution," or a "Project" ... we'll we won't touch that one ... :) ... end edit ... You create it, compile it, and, then, to use it "externally," you must reference it, by adding a Reference to the compiled .dll via the Solution Explorer/ References / Add Reference facility. The location of that compiled .dll can be anywhere: and the Add Reference dialog will let you browse to find it. Once the Reference is added: you do not need to have a 'using' statement for it to be accessed. The one "tool," not mentioned here, that may also be useful in "encapsulating functional units," is using NameSpaces: within one solution you can add Classes, etc., and encapsulate them in the scope of a different NameSpace. In that case, to access the "whatever inside" that NameSpace, you will need to have a "using" statement in your Form or whatever it is that requires access. Or, you can avoid having a "using," statement kby using a "fully qualified" reference: Example:
using SpecialNameSpace;
// now you can reference a class in SpecialNameSpace directly:
SpecialClass theSpecialClass = new SpecialClass();
// or ... without the "using" statement:
SpecialNameSpace.SpecialClass theSpecialClass = new SpecialNameSpace.SpecialClass();
However, when your solution, with multiple NameSpaces, is compiled, the resulting .exe incorporates everything: no separate files are created just by using different NameSpaces. I have never experimented with trying to import a compiled class library dll into another class library, but,
-
PIEBALDconsult wrote:
not required
Technically, yes. But this code
using Com.Company.Suite.Product.Version.Module;
MyClass c1 = new MyClass();
is more readable by an order of magnitude than this code
Com.Company.Suite.Product.Version.Module.MyClass c1 = new Com.Company.Suite.Product.Version.Module.MyClass();
Shameel wrote:
is more readable
I disagree, especially when code snippets are published here.
-
I think another way to "frame" this question ... if my intuition is on-line here ... is to ask: how can I design, or re-design, my getting-very-big project into functional units, or: how can I determine a set of "organic criteria" which to use as an "organizing principle" to divide my project into logical "chunks" which, in the long run, contribute to program extension, maintenance, and de-bugging (and lend themselves to unit-testing in "isolation" ?). All the "tools" mentioned here, including "Partial Classes," "Class Libraries," etc. are valuable. ... edit in appreciative response to feedback from PiebaldConsult ... Please note: in Visual Studio the option to create a "Class Library" is one that appears when you create a new Solution, and also appears as an option when you choose to add a "New Project" to an existing "Solution." The question of whether a "Solution," which "begins life" as "only" a "Class Library," is, semantically, a "Solution," or a "Project" ... we'll we won't touch that one ... :) ... end edit ... You create it, compile it, and, then, to use it "externally," you must reference it, by adding a Reference to the compiled .dll via the Solution Explorer/ References / Add Reference facility. The location of that compiled .dll can be anywhere: and the Add Reference dialog will let you browse to find it. Once the Reference is added: you do not need to have a 'using' statement for it to be accessed. The one "tool," not mentioned here, that may also be useful in "encapsulating functional units," is using NameSpaces: within one solution you can add Classes, etc., and encapsulate them in the scope of a different NameSpace. In that case, to access the "whatever inside" that NameSpace, you will need to have a "using" statement in your Form or whatever it is that requires access. Or, you can avoid having a "using," statement kby using a "fully qualified" reference: Example:
using SpecialNameSpace;
// now you can reference a class in SpecialNameSpace directly:
SpecialClass theSpecialClass = new SpecialClass();
// or ... without the "using" statement:
SpecialNameSpace.SpecialClass theSpecialClass = new SpecialNameSpace.SpecialClass();
However, when your solution, with multiple NameSpaces, is compiled, the resulting .exe incorporates everything: no separate files are created just by using different NameSpaces. I have never experimented with trying to import a compiled class library dll into another class library, but,
BillWoodruff wrote:
it is a type of Solution
It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.
-
BillWoodruff wrote:
it is a type of Solution
It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.
+5 Absolutely correct: interestingly, I've never created a Class Library that way. I have edited my response to incorporate your feedback, thanks. best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
-
Shameel wrote:
is more readable
I disagree, especially when code snippets are published here.
Code snippets with references to 3rd-party/programmer-created namespaces is kinda pointless anyway. And who are you calling weak? :)
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
+5 Absolutely correct: interestingly, I've never created a Class Library that way. I have edited my response to incorporate your feedback, thanks. best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
YOU'RE WEAK! :)
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Shameel wrote:
is more readable
I disagree, especially when code snippets are published here.
PIEBALDconsult wrote:
I disagree, especially when code snippets are published here.
Well, the vast majority of code that we write goes into some commercial project rather than CP posts. Repeating the fully qualified type name of class everywhere it is used makes no sense especially when VS (and SD for that matter) tell you the fully qualified type name just by hovering the mouse over it.
-
PIEBALDconsult wrote:
I disagree, especially when code snippets are published here.
Well, the vast majority of code that we write goes into some commercial project rather than CP posts. Repeating the fully qualified type name of class everywhere it is used makes no sense especially when VS (and SD for that matter) tell you the fully qualified type name just by hovering the mouse over it.
Shameel wrote:
the vast majority of code that we write goes into some commercial project rather than CP posts
Yet the vast majority of code I see that I didn't write is in CP posts.
Shameel wrote:
VS (and SD
Which I don't use if I can avoid it. I also prefer to print out code so I can review it away from the computer.
-
YOU'RE WEAK! :)
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997“Keep me away from the wisdom which does not cry, the philosophy which does not laugh and the greatness which does not bow before children.” Kahlil Gibran Happy Holidays, John ! :) best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle