Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1440 of 2650
4K+ Views
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 More
2K+ Views
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 More
4K+ Views
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 More
2K+ Views
The process of injecting (converting) coupled (dependent) objects into decoupled (independent) objects is called Dependency Injection.Types of Dependency InjectionThere are four types of DI:1.Constructor Injection2.Setter Injection3.Interface-based injection4.Service Locator InjectionConstructor InjectionConstructor is used to interface parameter that exposed through the parameterized contractor.It injects the dependencies through a contractor method as object creation other classes.Setter InjectionGetter and Setter Injection injects the dependency by using default public properties procedure such as Gettter(get(){}) and Setter(set(){}). TInterface InjectionInterface Injection is similar to Getter and Setter DI, the Getter and Setter DI uses default getter and setter but Interface Injection uses support interface a kind of ... Read More
3K+ Views
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 More
712 Views
Subsetting of a data frame can be done in many ways and one such say is selecting the columns that are stored in a vector. Suppose we have a data frame df that has columns x, y, and z and the column names y and z are stored in a vector called V then we can subset df by excluding column names in V as select(df, -all_of(V)).ExampleConsider the below data frame:Live Demo> x1 x2 x3 x4 df1 df1Outputx1 x2 x3 x4 1 3 4 0 5 2 4 1 2 6 3 4 1 2 3 4 8 1 7 ... Read More
651 Views
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 More
4K+ Views
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 More
181 Views
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:
1K+ Views
The mean of row values can be found by using rowwise function of dplyr package along with the mutate function to add the new column of means in the data frame. The rowwise function actually helps R to read the values in the data frame rowwise and then we can use mean function to find the means as shown in the below examples.Example1Consider the below data frame:Live Demo> x1 x2 df1 df1Output x1 x2 1 0 8 2 2 3 3 2 5 4 0 5 5 3 2 6 0 10 7 3 5 8 1 7 9 0 ... Read More