Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Nizamuddin Siddiqui
Page 110 of 196
How to get all the directories and sub directories inside a path in C#?
To get the directories C# provides a method Directory.GetDirectories. The Directory.GetDirectories method returns the names of the subdirectories (including their paths) that match the specified search pattern in the specified directory, and optionally searches subdirectories.In the below example * is matches Zero or more characters in that position. SearchOption TopDirectoryOnly .Gets only the top directories and SearchOption AllDirectories .Gets all the top directories and sub directories.Note: The rootPath will be your systems rootPath so create a testfolder and use the rootPath accoridingly.Example 1static void Main (string[] args) { string rootPath = @"C:\Users\Koushik\Desktop\TestFolder"; string[] dirs = Directory.GetDirectories(rootPath, "*", SearchOption.TopDirectoryOnly); ...
Read MoreHow to convert IEnumerable to List and List back to IEnumerable in C#?
IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface. It is the base interface for all non-generic collections that can be enumerated.This works for read-only access to a collection that implements that IEnumerable can be used with a foreach statement.List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace.List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists.Example 1static void Main(string[] args) { List list = new ...
Read MoreHow to check Minlength and Maxlength validation of a property in C# using Fluent Validation?
MaxLength ValidatorEnsures that the length of a particular string property is no longer than the specified value.Only valid on string propertiesString format args:{PropertyName} = The name of the property being validated{MaxLength} = Maximum length{TotalLength} = Number of characters entered{PropertyValue} = The current value of the propertyMinLength ValidatorEnsures that the length of a particular string property is longer than the specified value.Only valid on string properties{PropertyName} = The name of the property being validated{MinLength} = Minimum length{TotalLength} = Number of characters entered{PropertyValue} = The current value of the propertyExamplestatic void Main(string[] args){ List errors = new List(); PersonModel ...
Read MoreHow to valid DateofBirth using fluent Validation in C# if it exceeds current year?
To specify a validation rule for a particular property, call the RuleFor method, passing a lambda expression that indicates the property that you wish to validateRuleFor(p => p.DateOfBirth)To run the validator, instantiate the validator object and call the Validate method, passing in the object to validate.ValidationResult results = validator.Validate(person);The Validate method returns a ValidationResult object. This contains two propertiesIsValid - a boolean that says whether the validation suceeded.Errors - a collection of ValidationFailure objects containing details about any validation failuresExample 1static void Main(string[] args) { List errors = new List(); PersonModel person = new PersonModel(); person.FirstName ...
Read MoreWhat is use of fluent Validation in C# and how to use in C#?
FluentValidation is a .NET library for building strongly-typed validation rules. It Uses a fluent interface and lambda expressions for building validation rules. It helps clean up your domain code and make it more cohesive, as well as giving you a single place to look for validation logicTo make use of fluent validation we have to install the below packageExample 1static class Program { static void Main (string[] args) { List errors = new List(); PersonModel person = new PersonModel(); person.FirstName = ""; person.LastName = "S"; ...
Read MoreHow to copy files into a directory in C#?
To Copy a file, C# provides a method File. CopyFile. Copy has 2 overloadsCopy(String, String) -Copies an existing file to a new file. Overwriting a file of the same name is not allowed.Copy(String, String, Boolean) Copies an existing file to a new file. Overwriting a file of the same name is allowed.Directory.GetFiles returns the names of all the files (including their paths) that match the specified search pattern, and optionally searches subdirectories.Examplestatic void Main (string[] args) { string rootPath = @"C:\Users\Koushik\Desktop\TestFolder\TestFolderMain1"; var searchSourceFolder = Directory.GetFiles(rootPath, "*.*", SearchOption.TopDirectoryOnly); Console.WriteLine("-------------Source Folder-------------"); foreach (string file in searchSourceFolder){ ...
Read MoreHow to convert XML to Json and Json back to XML using Newtonsoft.json?
Json.NET supports converting JSON to XML and vice versa using the XmlNodeConverter.Elements, attributes, text, comments, character data, processing instructions, namespaces, and the XML declaration are all preserved when converting between the twoSerializeXmlNodeThe JsonConvert has two helper methods for converting between JSON and XML. The first is SerializeXmlNode(). This method takes an XmlNode and serializes it to JSON text.DeserializeXmlNodeThe second helper method on JsonConvert is DeserializeXmlNode(). This method takes JSON text and deserializes it into an XmlNode.Example 1static void Main(string[] args) { string xml = @"Alanhttp://www.google1.com Admin1"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string json = JsonConvert.SerializeXmlNode(doc); ...
Read MoreHow to convert a named vector to a list in R?
A named vector cannot be directly converted to a list because we would need to un-name the vector names and convert those names to names of the list elements. This can be done by using lapply function function. For example, suppose we have a named vector x then it can be converted to a list by using the command x x1 names(x1) x1OutputA B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 10 11 12 ...
Read MoreHow to find the correlation coefficient between two data frames in R?
If two data frames in R have equal number of columns then we can find the correlation coefficient among the columns of these data frames which will be the correlation matrix. For example, if we have a data frame df1 that contains column x and y and another data frame df2 that contains column a and b then the correlation coefficient between df1 and df2 can be found by cor(df1, df2).Example1Consider the below data frame:Live Demo> x1 x2 df1 df1Output x1 x2 1 39.56630 38.25632 2 39.43689 44.14647 3 40.80479 37.43309 ...
Read MoreHow to add a straight line to a plot in R starting from bottom left and ending at top right?
The abline function can give us a straight line from intercept 0 with slope 1 in an existing plot. We would need to pass the coefficients inside the function as abline(coef = c(0,1)). Therefore, we can use this function to add a line starting from bottom left and ending at top right. This is also called diagonal line because it joins the end points on one side with the opposite of the other side.Example> plot(1:10,type="n") > abline(coef=c(0,1))Output:
Read More