Csharp Articles

Page 109 of 196

Overloaded method and ambiguity in C#

George John
George John
Updated on 17-Mar-2026 1K+ Views

With method overloading, you can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. However, when using default parameters with overloaded methods, ambiguity can occur if the compiler cannot determine which method to call. Syntax Following is the syntax for method overloading − public void MethodName(int parameter1) { // Implementation 1 } public void MethodName(int parameter1, int parameter2) { // Implementation 2 ...

Read More

Print with your own font using C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 543 Views

To print with your own font in C#, you need to construct two essential objects: a FontFamily object and a Font object. The FontFamily object sets the typeface like Arial, Times New Roman, etc., whereas the Font object defines the size, style, and unit of measurement for the font. Syntax Following is the syntax for creating a FontFamily object − FontFamily fontFamily = new FontFamily("FontName"); Following is the syntax for creating a Font object − Font font = new Font(fontFamily, size, style, unit); Parameters The Font constructor accepts the ...

Read More

Print Single and Multiple variable in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 10K+ Views

In C#, displaying variable values to the console is fundamental for debugging and output purposes. You can print single or multiple variables using various methods with Console.WriteLine(). Syntax Following is the syntax for printing a single variable − Console.WriteLine(variable); Console.WriteLine("Text: " + variable); Following is the syntax for printing multiple variables − Console.WriteLine("Values: {0} {1}", var1, var2); Console.WriteLine($"Values: {var1} {var2}"); Printing a Single Variable You can print a single variable by passing it directly to Console.WriteLine() or by concatenating it with text using the + operator − ...

Read More

Priority Queues with C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 325 Views

A priority queue is a data structure that stores elements with associated priority values. It is an extension of a regular queue where elements are served based on their priority rather than their insertion order. When you remove an item from a priority queue, the element with the highest priority is removed first. If two elements have the same priority, they are typically served in the order they were inserted. Syntax Following is the basic syntax for creating a priority queue class − public class MyPriorityQueue where T : IComparable { private ...

Read More

Private Constructors and Singleton Classes in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

A private constructor is a constructor that cannot be called from outside the class. It is primarily used in classes containing only static members or to implement the Singleton design pattern, which ensures that only one instance of a class can exist throughout the application's lifetime. Syntax Following is the syntax for declaring a private constructor − class ClassName { private ClassName() { // private constructor body } } Private Constructor for Static-Only Classes When a class contains only static members, ...

Read More

Optimization Tips for C# Code

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 888 Views

C# code optimization involves writing efficient code that executes faster and uses memory more effectively. Here are essential optimization tips that can significantly improve your application's performance. Prefer Generic Collections Over Non-Generic Use List instead of ArrayList whenever possible. Generic collections provide type safety and better performance by avoiding boxing and unboxing operations − using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; class Program { public static void Main() { // Inefficient - ArrayList with boxing ArrayList arrayList = new ...

Read More

Private Variables in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 7K+ Views

The private access specifier in C# allows a class to hide its member variables and member functions from other functions and objects. Only methods of the same class can access its private members. Even an instance of a class cannot access its private members directly from outside the class. Syntax Following is the syntax for declaring a private variable − private dataType variableName; For example − private double length; private int count; private string name; Key Rules of Private Variables Private members can only be accessed within ...

Read More

Optional property in a C# class

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 5K+ Views

An optional property in a C# class is a property that can have a null value without causing runtime errors. Properties whose CLR types cannot hold null values (like value types) cannot be configured as optional unless they are made nullable using the ? operator. Optional properties are commonly implemented using nullable reference types, default values, or custom attributes to indicate that the property is not required to have a value. Syntax Following is the syntax for declaring nullable properties − public string? PropertyName { get; set; } // Nullable reference type ...

Read More

Mutation Test tools in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 368 Views

Mutation testing is a software testing technique that evaluates the quality of your test suite by introducing small code changes (mutations) and checking if your tests can detect these changes. In C#, several tools are available to perform mutation testing effectively. What is Mutation Testing? Mutation testing works by creating mutants − modified versions of your source code with small, intentional bugs. A good test suite should detect these mutations and fail when run against the mutated code. The mutation score represents the percentage of mutants killed (detected) by your tests. Mutation Testing ...

Read More

Naming Conventions in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

Naming conventions in C# help maintain code readability and consistency across projects. Following standardized naming patterns makes your code more professional and easier to understand for other developers. Class Naming Conventions A class definition starts with the class keyword followed by the class name, enclosed by curly braces. The following conventions apply to class names. Pascal Casing Class names should use PascalCasing, where the first letter of each word is capitalized − public class EmployeeDetails { } public class BankAccount { } public class CustomerOrderHistory { } Noun or Noun Phrases ...

Read More
Showing 1081–1090 of 1,951 articles
« Prev 1 107 108 109 110 111 196 Next »
Advertisements