Found 27759 Articles for Server Side Programming

Decision Making in C#

George John
Updated on 23-Jun-2020 09:27:14

153 Views

Decision making structures requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.Decision Making in C# includes if statement, if-else statement, switch statement, etc.Let us see an example of if statement in C#.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          int x = 5;       ... Read More

Constructors in C#

karthikeya Boyini
Updated on 23-Jun-2020 09:27:50

343 Views

A Constructor in C# gets invoked automatically when a object gets created. The constructor has the same name as that of the class, for example −public class Department {    public Department () {       Console.WriteLine("Default Constructor! ");    } }The following is the code that shows the usage of constructor in C#.Example Live Demousing System; public class Department {    public Department () {       Console.WriteLine("Constructor Invoked");    }    public static void Main(string[] args) {       Department dept1 = new Department ();    } }OutputConstructor Invoked

Constructor Overloading in C#

Ankith Reddy
Updated on 23-Jun-2020 09:14:03

2K+ Views

When more than one constructor with the same name is defined in the same class, they are called overloaded, if the parameters are different for each constructor.Let us see an example to learn how to work with Constructor Overloading in C#.In the example, we have two subjects and a string declaration for Student Name.private double SubjectOne; private double SubjectTwo; string StudentName;We are showing result of three students in different subjects. For our example, to show constructor overloading, the name is only displayed for student 3rd.Student s1 = new Student(); Student s2 = new Student(90); Student s3 = new Student("Amit", 88, ... Read More

Compound assignment operators in C#

Samual Sam
Updated on 23-Jun-2020 09:14:59

3K+ Views

A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.The following are the compound assignment operators in C#.Sr.NoOperator & Operator Name1+=Addition Assignment2-=Subtraction Assignment3*=Multiplication Assignment4/=Division Assignment5%=Modulo Assignment6&=Bitwise AND Assignment7|=Bitwise OR Assignment8^=Bitwise XOR Assignment9=Right Shift Assignment11=>Lambda OperatorLet us see an example to learn how to work with compound assignment operators in C#.Example Live Demousing System; namespace Program {    class MyClass {       public static void Main(string[] args) {          int val = 7;          val ... Read More

Composition vs Aggregation in C#

Arjun Thakur
Updated on 23-Jun-2020 09:16:12

2K+ Views

CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine {    . . . } public class Car {    Engine eng = new Engine();    ....... }AggregationAggregation is a directional relation between objects in C#. It is the relationship between objects.For example, Employee and AddressAn Employee is associated with a single Department, whereas a Department can have more than one employee. Let us see ... Read More

Compilation and Execution of a C# Program

Chandu yadav
Updated on 30-Jul-2019 22:30:23

18K+ Views

To compile and execute a program in C#, you just need to click the Run button or press F5 key to execute the project in Microsoft Visual Studio IDE. Compile a C# program by using the command-line instead of the Microsoft Visual Studio IDE − Open a text editor and add the above-mentioned code. Save the file as helloworld.cs Open the command prompt tool and go to the directory where you saved the file. Type csc helloworld.cs and press enter to compile your code. If there are no errors in your code, the command prompt takes you to the next line and ... Read More

Complex Numbers in C#

karthikeya Boyini
Updated on 23-Jun-2020 09:17:01

2K+ Views

To work WITH and display complex numbers in C#, you need to check for real and imaginary values.A complex number like 7+5i is formed up of two parts, a real part 7, and an imaginary part 5. Here, the imaginary part is the multiple of i.To display complete numbers, use the −public struct ComplexTo add both the complex numbers, you need to add the real and imaginary part −public static Complex operator +(Complex one, Complex two) {    return new Complex(one.real + two.real, one.imaginary + two.imaginary); }You can try to run the following code to work with complex numbers in ... Read More

C# Enum GetValues Method

Arjun Thakur
Updated on 23-Jun-2020 09:18:16

1K+ Views

Get the array of the values of the constants in a specified enumeration.Here is our enum.enum Rank { Jack = 10, Tom = 19, Tim = 26 };Now, get all the values of the enum as an array and display using GetValues() method.foreach(int res in Enum.GetValues(typeof(Rank))) {    Console.WriteLine(res); }Let us see the entire example.Example Live Demousing System; public class Demo {    enum Rank { Jack = 10, Tom = 19, Tim = 26 };    public static void Main() {       Console.WriteLine("Here are the university rank of MCA Students College ABC:");       foreach(int res in ... Read More

C# Program to get the type of the specified Enumeration

Samual Sam
Updated on 23-Jun-2020 09:18:47

102 Views

Use the GetType() method to get the type of the enumeration.The enumeration.Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday};Now to get the type, use the GetType() method.Type enumType = val.GetType();The following is an example that displays the type.Example Live Demousing System; public class Demo {    public static void Main() {       Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday};       Console.WriteLine("{0, -5} {1, 10} {2, 10}", "Member", "Enumeration", "UnderlyingType");       foreach (var val in values)       Info(val);    }    static void Info(Enum val) {       Type enumType = val.GetType();       Type ... Read More

C# Enum GetNames Method

Chandu yadav
Updated on 23-Jun-2020 09:19:20

738 Views

The GetNames() returns the array of names of the constants in the Enumeration.The following is the enum.enum Stock { Watches, Books, Grocery };To get the array of names, use the GetNames() and loop through as shown below −foreach(string s in Enum.GetNames(typeof(Stock))) { }Let us see the complete example now.Example Live Demousing System; class Demo {    enum Stock { Watches, Books, Grocery };    static void Main() {       Console.WriteLine("The value of first stock category = {0}", Enum.GetName(typeof(Stock), 0));       Console.WriteLine("The value of second stock category = {0}", Enum.GetName(typeof(Stock), 1));       Console.WriteLine("The value of third ... Read More

Advertisements