Csharp Articles - Page 136 of 258

Decimal Functions in C#

Chandu yadav
Updated on 23-Jun-2020 09:44:15

285 Views

The following are some of the decimal functions in C#.Sr.No.Name & Description1Add (Decimal, Decimal)Adds two specified Decimal values.2Ceiling(Decimal)Returns the smallest integral value that is greater than or equal to the specified decimal number.3Compare (Decimal, Decimal)Compares two specified Decimal values.4CompareTo(Decimal)Compares this instance to a specified Decimal object and returns a comparison of their relative values.5CompareTo(Object)Compares this instance to a specified object and returns a comparison of their relative values.6Divide (Decimal, Decimal)Divides two specified Decimal values.7Equals(Decimal)Returns a value indicating whether this instance and a specified Decimal object represent the same value.Let us see an example of Decimal Ceiling() method in C# that returns the smallest integral value greater than or equal to ... Read More

Coupling in C#

George John
Updated on 14-Apr-2020 11:09:33

3K+ Views

Coupling shows the relationship between modules in C# or you can say the interdependence between modules.There are two types of coupling i.e tight and loose coupling.Loose CouplingLoose coupling is preferred since through it changing one class will not affect another class. It reduces dependencies on a class. That would mean you can easily reuse it.Writing loosely coupled code has the following advantages −One module won’t break other modulesEnhances testabilityCode is easier to maintainGets less affected by changes in other components.Tight CouplingIn Tight Coupling, the classes and objects are dependent on each other and therefore reduce re-usability of code.Read More

Database Operations in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

The most common databases used in C# are Microsoft SQL Server and Oracle. The following is done to work with databases. Connect Set the Database Name, Optional Parameters and Credentials. The username and password is needed to set a connection to the database. The connection string would look somewhat like this. private static string _connectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=test;Application Name=Demo;Connection Timeout2w00"; Above, the Application Name is Demo. Select Statement To fetch data from the database, the SELECT statement is used Insert The INSERT command is used to insert data in the database. Update The database ... Read More

Counters in C#

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

2K+ Views

Counters in C# are performance counters that lets you know about your applications performance. When you will build an application, whether it is a web app, mobile app or even desktop app, you would definitely need to monitor the performance. For performance counters in C#, use the System.Diagnostics.PerformanceCounter class. Set the instance of the PerformanceCounter class and work with the following properties: CategoryName, CounterName, MachineName and ReadOnly. To get the performance categories. var counter = PerformanceCounterCategory.GetCategories(); Now SET performance counters for the category processor. var counter = PerformanceCounterCategory.GetCategories() .FirstOrDefault(category => category.CategoryName == "Processor");

Date Class in C#

karthikeya Boyini
Updated on 23-Jun-2020 09:49:22

14K+ Views

To set dates in C#, use DateTime class. The DateTime value is between 12:00:00 midnight, January 1, 0001 to 11:59:59 P.M., December 31, 9999 A.D.Let’s create a DateTime object.Example Live Demousing System; class Test {    static void Main() {       DateTime dt = new DateTime(2018, 7, 24);       Console.WriteLine (dt.ToString());    } }Output7/24/2018 12:00:00 AMLet us now get the current date and time.Example Live Demousing System; class Test {    static void Main() {       Console.WriteLine (DateTime.Now.ToString());    } }Output9/17/2018 5:49:21 AMNow using the method Add(), we will add days in a date with the ... Read More

Events vs Delegates in C#

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

568 Views

C# events are used to resolve the hassles in Delegates. One an easily override Delegate properties and that can eventually lead to errors in the code. To avoid this, C# uses Events and defines wrappers around Delegates. Events in C# To use Event, you should define delegate first. Event is a type of Delegate and an example of event can be when a key is pressed. public delegate voide Demo(String val); public event Test TestEvent; An event can hold a delegate like this. this.TestEvent += new Demo (DemoData); ... Read More

Enqueue and deque in Queue class in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

973 Views

Queue collection class is a concept in C# that is included in the System.Collection namespace. The elements are stored in a QUEUE in FIFO. The first element added will be the first to go out like a queue of people outside a movie hall to buy tickets. It has two methods. Enqueue() method to add values Dequeue() method to retrieve values Enqueue Add items in the queue. Queue q = new Queue(); q.Enqueue(“Two”); q.Enqueue(“One”); Dequeue Return items from the queue. Queue q = new Queue(); q.Enqueue(“Two”); q.Enqueue(“One”); // remove elements while (q.Count > 0) ... Read More

Equivalent of Java Super Keyword in C#

Chandu yadav
Updated on 23-Jun-2020 09:37:08

8K+ Views

For super keyword in Java, we have the base keyword in C#.Super keyword in Java refers immediate parent class instance. It is used to differentiate the members of superclass from the members of subclass, if they have same names. It is used to invoke the superclass constructor from subclass.C# base keyword is used to access the constructors and methods of base class. Use it within instance method, constructor, etc.Let us see an example of C# base.Example Live Demousing System; public class Animal {    public string repColor = "brown"; } public class Reptile: Animal {    string repColor = "green";   ... Read More

Delegation vs Inheritance in C#

Samual Sam
Updated on 23-Jun-2020 09:37:53

759 Views

Delegates in C#A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.To declare a delegate.delegate Delegation has run-time flexibility i.e. you can easily change it at runtime. The instance you create in Delegation is of a known class.Inheritance in C#Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.When creating a class, instead of writing completely new data members and ... Read More

Difference between Static Constructor and Instance Constructor in C#

George John
Updated on 23-Jun-2020 09:38:41

855 Views

Static ConstructorA static constructor is a constructor declared using static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.Instance ConstructorInstance constructor initializes instance data. Instance constructor is called when an object of class is created.The following example shows the difference between static and instance constructor in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Difference {    class Demo {       static int val1;       int val2;       static Demo() {         ... Read More

Advertisements