Comprog 2
Comprog 2
BSEE 1-A
Assignment in Computer Programming
1. What is a Function in C#?
A function in C# is a block of code that performs a specific task. It can take input parameters, execute a
series of statements, and return a value. Functions in C# are also known as methods when they are part of
a class.
2. What are the Uses of Functions in C# Programming?
Functions in C# are used for several purposes:
- Code Reusability: Functions allow you to write a piece of code once and reuse it multiple times
throughout your application.
- Modularity: Functions help break down a large program into smaller, manageable, and more
understandable pieces.
- Maintainability: They make code easier to maintain and update since changes in functionality can be
made in one place.
- Testing: Functions can be tested independently, making it easier to debug and ensure correctness.
- Abstraction: They help abstract complex operations behind a simple interface, making the code more
readable.
3. Create a Simple Program Code
a) Using One Function
b) Using Two Functions
c) Using Three Functions
References
- https://www.programiz.com/csharp-programming/online-compiler/
- Microsoft Docs: [Methods (C# Programming Guide)](https://docs.microsoft.com/en-
us/dotnet/csharp/programming-guide/classes-and-structs/methods)
- W3Schools: [C# Methods](https://www.w3schools.com/cs/cs_methods.php)
- TutorialsTeacher: [C# Methods](https://www.tutorialsteacher.com/csharp/csharp-methods)