current location:Home > Technical Articles > Backend Development > C#.Net Tutorial
- Direction:
- All web3.0 Backend Development Web Front-end Database Operation and Maintenance Development Tools PHP Framework Daily Programming WeChat Applet Common Problem Other Tech CMS Tutorial Java System Tutorial Computer Tutorials Hardware Tutorial Mobile Tutorial Software Tutorial Mobile Game Tutorial
- Classify:
-
- C# program to determine whether a number is divisible by 2
- If the remainder of dividing this number by 2 is 0, then it is divisible by 2. Assuming our number is 5, we will use the following if-else to check it - //checkingifthenumberisdivisibleby2ornotif(num%2==0){ Console.WriteLine("Divisibleby2");}else{ Console.WriteLine("Notdivisibleby2") ;} Example below is
- C#.Net Tutorial 1318 2023-09-05 22:53:06
-
- What are AddSingleton, AddScoped and Add Transient C# Asp.net Core?
- There are three ways to register dependencies in Startup.cs. ie. AddSingleton, AddScoped and AddTransient. Adding a Singleton When we register a type as a singleton, only one instance is available throughout the process. applicationandforevery request. It is similar to having a static object. The instance is created for the first request and the same is available throughout the application and every subsequent request. pub
- C#.Net Tutorial 1583 2023-09-05 22:21:17
-
- C# program to reverse string
- Our example string is - myStr="Tom"; To reverse the string, first find the length of the string −//findstringlengthintlen; len=myStr.Length-1; Now, use a while loop until the length is greater than 0 - while (len>=0){ rev=rev+myStr[len]; len--;} Example You can try running the following code to reverse a string in C#. Live demonstration usingSystem;cl
- C#.Net Tutorial 1324 2023-09-05 19:09:03
-
- C# program to check whether a path is a directory or a file
- Introduction Let us learn how to write a C# program to check whether a path is a directory or a file. A directory, also called a folder, is a location on your computer where files can be saved. In addition to files, directories also contain other directories or shortcuts. A file is a collection of data on a drive that has a unique identifier and directory path. When a file is opened for viewing or writing, it is converted to a stream. A stream is simply a sequence of bytes traversing a communication path. Files and Directories Files are real data files, while directories are repositories where logical files are placed on the system. To handle files and directories, the common language runtime (CLR) has classes File, FileInfo, Directory, and DirectoryInfo in the System.IO namespace. for
- C#.Net Tutorial 625 2023-09-05 17:49:02
-
- How to catch out of memory exception in C#?
- System.OutOfMemoryException occurs when the CLR cannot allocate enough memory required. System.OutOfMemoryException inherits from the System.SystemException class. Set the string - stringStudentName="Tom"; stringStudentSubject="Maths"; Now you need to initialize with the allocated capacity, i.e. the length of the initial value - StringBuildersBuilder=newStringBuilder(Stud
- C#.Net Tutorial 1064 2023-09-05 16:09:07
-
- What is binary serialization and deserialization in C# and how to implement binary serialization in C#?
- Converting an object into an unreadable binary format is called binary serialization. Converting a binary format back to a readable format is called deserialization? To implement binary serialization in C# we have to use the library System.Runtime.Serialization.Formatters.BinaryAssembly. Create an object of BinaryFormatter class and use the serialize method inside the class. ExampleSerializeanObjecttoBinary[Serializable]publicclassDemo{ publicstr
- C#.Net Tutorial 1391 2023-09-05 15:53:02
-
- Collections in C#
- A collection in C# is a HashSet. HashSet in C# eliminates duplicate strings or elements in an array. In C#, it is an optimized set collection declaration HashSet-varh=newHashSet<string>(arr1); Above, we have set the declared array arr1 in the HashSet. Now set it on an array to remove duplicate words - string[]arr2=h.ToArray(); Let us see an example of removing duplicate strings using C# HashSet. Here, we have repeated elements - example usingSystem;usingSystem.Colle
- C#.Net Tutorial 1492 2023-09-05 15:37:02
-
- What is a jagged array in C#?
- A jagged array is an array of arrays in C#. You can declare and initialize it - int[][]rank=newint[1][]{newint[]{5,3,1}}; The following example shows how to use jagged array in C# - Example usingSystem;namespaceProgram { classDemo{ staticvoidMain(string[]args){ &a
- C#.Net Tutorial 1312 2023-09-05 13:52:12
-
- What is the AddRange method in C# List?
- The AddRange method in a list adds the entire collection of elements. Let's see an example - First, set up a list in C# and add elements - List<int>list=newList<int>();list.Add(100);list.Add(200);list.Add(300 );list.Add(400);Now set the array of elements to be added to the list -//arrayof4elementsint[]arr=newint[4];arr[0]=500;arr[1]=600;arr[2] =700;arr[3]=800;Use Ad
- C#.Net Tutorial 1758 2023-09-05 12:41:02
-
- What is the proxy design pattern and how to implement it in C#?
- The proxy pattern provides a proxy or placeholder object to control access to a different object. Proxy objects are used in the same way as their containing objects. Participant Subject defines a public interface for RealSubject and Proxy so that Proxy can be used wherever RealSubject needs it. RealSubject defines the specific object represented by the Proxy. The proxy maintains a reference to the real subject and controls access to it. It must implement the same interface as RealSubject so that the two can be used interchangeably. If you've ever needed to change the behavior of an existing object without actually changing that object's definition, the proxy pattern allows you to do just that. Furthermore, this is
- C#.Net Tutorial 1302 2023-09-05 12:21:10
-
- C# program to check if HashTable collection is empty
- A Hashtable collection in C# is a collection of key-value pairs organized according to the hash code of the key. The hash code is calculated using the hash code function. Each element in a hash table is a key-value pair with a unique key. The key must also be non-null. Values can be empty and repeated. In this article, we will discuss how to check if a hash table collection is empty. How to check if hash table collection is empty? The class that implements a hash table collection in C# is the Hashtable class. We can check if the hash table collection is empty by counting the number of elements present in the hash table. For this we can use the "Count" property of the Hashtable class, which returns the number of elements in the hash table. So if the Count property returns 0, it means the hash table is empty
- C#.Net Tutorial 767 2023-09-05 11:17:02
-
- C# program to find client's IP address
- First find the host name using Dns.GetHostName() method in C# - StringhostName=string.Empty;hostName=Dns.GetHostName();Console.WriteLine("Hostname:"+hostName); Now, use IPHostEntry.AddressList property to get IP address-IPHostEntrymyIP=Dns.GetHostEntry(hostName);IPAddress[]address=myIP.Address
- C#.Net Tutorial 1162 2023-09-05 11:09:09
-
- How to add items to ArrayList in C#?
- ArrayList is a non-generic collection in C# that can be dynamically resized. Let us see how to initialize ArrayList in C# - ArrayListarr=newArrayList(); Add items to array list - ArrayListarr1=newArrayList(); arr1.Add(30); arr1.Add(70); Let us see how to use C# Complete example implementing ArrayList. Here we have two array lists. The second array list is appended to the first list. ExampleusingSystem;usingSystem.Collections;publiccla
- C#.Net Tutorial 987 2023-09-05 09:53:02
-
- What is the difference between overriding and hiding in C#?
- Here is the difference between overriding and hiding - hiding redefines the complete method, while overriding only redefines the implementation of the method. In an override, you can access the base class using the object overridden methods of the subclass. Shadow cannot access subclass methods. Shadowing is also called method hiding. The methods of the parent class can be used by the subclass without using the override keyword in the shadow. Subclasses have their own versions of the same functions. Under override, you can define behavior that is specific to the subclass type, which means that the subclass can implement the parent class methods as per its requirements.
- C#.Net Tutorial 1236 2023-09-04 23:49:02
-
- How is encapsulation implemented in C#?
- Encapsulation is achieved through the use of access specifiers. Access specifiers define the scope and visibility of class members. C# supports the following access specifiers: Public, Private, Protected, Internal, ProtectedInternal, etc. Encapsulation can be understood through private access specifier, which allows a class to hide its member variables and functions from other functions and objects. In the example below, we have length and width as variables assigned private access specifiers - example usingSystem;namespaceRectangleApplication{ classRectan
- C#.Net Tutorial 1328 2023-09-04 23:17:02