Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 186 of 196

What is the difference between Func delegate and Action delegate in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 2K+ Views

A delegate is a type that represents references to methods with a particular parameter list and return type. When we instantiate a delegate, we can associate its instance with any method with a compatible signature and return type. We can invoke (or call) the method through the delegate instance.Func DelegateFunc is a generic delegate included in the System namespace. It has zero or more input parameters and one out parameter. The last parameter is considered as an out parameter. This delegate can point to a method that takes up to 16 Parameters and returns a value.Below is the Func delegate ...

Read More

How to create a folder if it does not exist in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 13K+ Views

For creating a directory, we must first import the System.IO namespace in C#. The namespace is a library that allows you to access static methods for creating, copying, moving, and deleting directories.It is always recommended to check if the Directory exist before doing any file operation in C# because the complier will throw exception if the folder does not exist.Exampleusing System; using System.IO; namespace DemoApplication {    class Program {       static void Main(string[] args) {          string folderName = @"D:\Demo Folder";          // If directory does not exist, create it   ...

Read More

How to convert C# DateTime to “YYYYMMDDHHMMSS” format?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 5K+ Views

Convert the dateTime to toString that results in converting the DateTime to “YYYYMMDDHHMMSS” formatThere are also other formats that the dateTime can be convertedMM/dd/yyyy 08/22/2020dddd, dd MMMM yyyy Tuesday, 22 August 2020dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2020 06:30dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2020 06:30 AMdddd, dd MMMM yyyy H:mm Tuesday, 22 August 2020 6:30dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2020 6:30 AMdddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2020 06:30:07MM/dd/yyyy HH:mm 08/22/2020 06:30MM/dd/yyyy hh:mm tt 08/22/2020 06:30 AMMM/dd/yyyy H:mm 08/22/2020 6:30MM/dd/yyyy h:mm tt 08/22/2020 6:30 AMMM/dd/yyyy HH:mm:ss 08/22/2020 06:30:07Example Live ...

Read More

How to check if a number is a power of 2 in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 683 Views

A power of 2 is a number of the form 2n where n is an integerThe result of exponentiation with number two as the base and integer n as the exponent.n2n01122438416532Example 1 Live Democlass Program {    static void Main() {       Console.WriteLine(IsPowerOfTwo(9223372036854775809));       Console.WriteLine(IsPowerOfTwo(4));       Console.ReadLine();    }    static bool IsPowerOfTwo(ulong x) {       return x > 0 && (x & (x - 1)) == 0;    } }OutputFalse TrueExample 2 Live Democlass Program {    static void Main() {       Console.WriteLine(IsPowerOfTwo(9223372036854775809));       Console.WriteLine(IsPowerOfTwo(4));       Console.ReadLine();    }    static bool IsPowerOfTwo(ulong n) {       if (n == 0)          return false;       while (n != 1) {          if (n % 2 != 0)             return false;          n = n / 2;       }       return true;    } }OutputFalse True

Read More

How do you do a deep copy of an object in .NET?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 197 Views

Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicatedDeep Copy is used to make a complete deep copy of the internal reference types.In another words a deep copy occurs when an object is copied along with the objects to which it refersExample Live Democlass DeepCopy {    public int a = 10; } class Program {    static void Main() {       //Deep Copy       DeepCopy d = new DeepCopy();       d.a = 10;       DeepCopy d1 = new ...

Read More

What is typeof, GetType or is in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 1K+ Views

Typeof()The type takes the Type and returns the Type of the argument.GetType()The GetType() method of array class in C# gets the Type of the current instance.isThe "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.Example Live Democlass Demo { } class Program {    static void Main() {       var demo = new Demo();       Console.WriteLine($"typeof { typeof(Demo)}");       Type tp = demo.GetType();       Console.WriteLine($"GetType {tp}");       if (demo is Demo) {         ...

Read More

How to implement a Singleton design pattern in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 594 Views

Singleton Pattern belongs to Creational type patternSingleton design pattern is used when we need to ensure that only one object of a particular class is Instantiated. That single instance created is responsible to coordinate actions across the application.As part of the Implementation guidelines we need to ensure that only one instance of the class exists by declaring all constructors of the class to be private. Also, to control the singleton access we need to provide a static property that returns a single instance of the object.ExampleSealed ensures the class being inherited and object instantiation is restricted in the derived classPrivate ...

Read More

What is the difference between Static class and Singleton instance in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 1K+ Views

StaticStatic is a keywordStatic classes can contain only static membersStatic objects are stored in stack.Static cannot implement interfaces, inherit from other classesSingletonSingleton is a design patternSingleton is an object creational pattern with one instance of the classSingleton can implement interfaces, inherit from other classes and it aligns with the OOPS conceptsSingleton object can be passed as a referenceSingleton supports object disposalSingleton object is stored on heapSingleton objects can be clonedSingleton objects are stored in Heap

Read More

Python - Write multiple files data to master file

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 612 Views

File handling is an important part of any web application.Python has several functions for creating, reading, updating, and deleting files.To write to an existing file, you must add a parameter to the open()function −"a" − Append − will append to the end of the file"w" − Write − will overwrite any existing contentExampleimport os # list the files in directory lis = os.listdir('D:\python' '\data_files\data_files') print(lis) tgt = os.listdir('D:\python' '\data_files\target_file')   file_dir ='D:\python\data_files\data_files' out_file = r'D:\python\data_files\target_file\master.txt' ct = 0   print('target file :', tgt) try:    # check for if file exists    # if yes delete the file    # otherwise ...

Read More

Python - Working with .docx module

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Aug-2020 9K+ Views

Word documents contain formatted text wrapped within three object levels. Lowest level- Run objects, Middle level- Paragraph objects and Highest level- Document object.So, we cannot work with these documents using normal text editors. But we can manipulate these word documents in python using the python-docx module.The first step is to install this third-party module python-docx. You can use pip “pip install python-docx”After installation import “docx” NOT “python-docx”.Use “docx.Document” class to start working with the word document.Example# import docx NOT python-docx import docx # create an instance of a word document doc = docx.Document() # add a heading of level 0 ...

Read More
Showing 1851–1860 of 1,958 articles
« Prev 1 184 185 186 187 188 196 Next »
Advertisements