- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2628 Articles for Csharp
1K+ Views
Our string is − string str = " My make "; Use the following regular expression to find the substring “make” @"\bmake\b" Here is the complete code − Example Live Demo using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); ... Read More
1K+ Views
To make code reusable in C#, use Interfaces. Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.For example, Shape Interface −public interface IShape { void display(); }Above we have declared an Interface Shape. You can notice that it begins with a capital “I”. It is a common convention that interfaces names begin with “I”.We have not added an access specifier above ... Read More
13K+ Views
Set a list −List < string > list1 = new List < string > () { "Lawrence", "Adams", "Pitt", "Tom" };Now use the Contains method to check if an item exits in a list or not.if (list1.Contains("Adams") == true) { Console.WriteLine("Item exists!"); }The following is the code to check if an item exists in a C# list or not.Exampleusing System; using System.Collections.Generic; public class Program { public static void Main() { List < string > list1 = new List < string > () { "Lawrence", ... Read More
252 Views
The Logistic regression is a linear model used for binomial regression. It is used in medical science and to predict a customer’s tendency to purchase a product. It makes use of predictor variables for this purpose.Logistic Regression allows easier analysis of results in the form of odds ratios and statistical hypothesis testing.A generalized linear model has taken input for a non-linear link function. The linear model has the following form −z = c1x1 + c2x2 + … cnxn + i = ct x + iHere,c is the coefficient vector, i is the intercept value x is the observation vector
15K+ Views
Use the Contains() method to check if a string contains a word or not.Set the string −string s = "Together we can do so much!";Now let’s say you need to find the word “much”if (s.Contains("much") == true) { Console.WriteLine("Word found!"); }Let us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { string s = "Together we can do so much!"; if (s.Contains("much") == true) { Console.WriteLine("Word found!"); } else { Console.WriteLine("Word not found!"); } } }OutputWord found!
4K+ Views
Use the Equals method to check if an item exists in a C# array.Set string and substring −string subStr = "pqrs"; string[] str = { "abcd", "ijkl", "pqrs", "wxyz" };Now check whether the substring is part of the string or not using the Equals method.if (item.Equals(subStr)) { Console.WriteLine("Item Found"); }Here is the complete code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(String[] args) { string subStr = "pqrs"; string[] str = { "abcd", "ijkl", "pqrs", "wxyz" }; foreach(string item in str) { if (item.Equals(subStr)) { Console.WriteLine("Item Found"); } } } } }OutputItem Found
587 Views
To get the maximum occurred character in a string, loop until the length of the given string and find the occurrence.With that, set a new array to calculate −for (int i = 0; i < s.Length; i++) a[s[i]]++; }The values we used above −String s = "livelife!"; int[] a = new int[maxCHARS];Now display the character and the occurrence −for (int i = 0; i < maxCHARS; i++) if (a[i] > 1) { Console.WriteLine("Character " + (char) i); Console.WriteLine("Occurrence = " + a[i] + " times"); }Let us see the complete code ... Read More
608 Views
To display multiple blank lines, we will take a while loop.Here, we are printing 10 blank lines using Console.WriteLine();while (a < 10) { Console.WriteLine(" "); a++; }The following is the complete code to display multiple blank lines −Exampleusing System; namespace Program { public class Demo { public static void Main(String[] args) { int a = 0; while (a < 10) { Console.WriteLine(" "); a++; } Console.WriteLine("Displayed 10 blank lines above!"); Console.ReadLine(); } } }
597 Views
To display a line, Console.Write() is used in C#.Console displays the result on the console. I have first set a string.string str = "Tom Hanks is an actor";Now displaying the above line.Console.WriteLine(str);The following is the complete code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(String[] args) { string str = "Tom Hanks is an actor"; Console.WriteLine("Displaying a line below"); Console.WriteLine(str); Console.ReadLine(); } } }OutputDisplaying a line below Tom Hanks is an actor
242 Views
With C#, you can easily display the following diamond shape.$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $To display a diamond shape, you need to focus on the following points −Number of rows Dollar sign to be displayed Empty spacesConsidering the above you can easily create the diamond shape as shown in the below code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(String[] args) { int i, j, r, d, e; // rows = 5 r = 5; // display dollar sign d = 1; // empty space e = r - 1; for (i = 1; i < r * 2; i++) { // display empty space for (j = 1; j