Found 2587 Articles for Csharp

C# program to check if a string contains any special character

Samual Sam
Updated on 19-Jun-2020 09:06:09

11K+ Views

To check if a string contains any special character, you need to use the following method −Char.IsLetterOrDigitUse it inside for loop and check or the string that has special characters.Let us say our string is −string str = "Amit$#%";Now convert the string into character array −str.ToCharArray();With that, use a for loop and to check for each character using the isLetterOrDigit() method.ExampleLet us see the complete code.Live Demousing System; namespace Demo {    class myApplication {       static void Main(string[] args) {          string str = "Amit$#%";          char[] one = str.ToCharArray();   ... Read More

C# Program to check if a number is prime or not

karthikeya Boyini
Updated on 10-Sep-2023 08:06:41

63K+ Views

To calculate whether a number is prime or not, we have used a for loop. Within that on every iteration, we use an if statement to find that the remainder is equal to 0, between the number itself.for (int i = 1; i

C# program to check for URL in a String

Samual Sam
Updated on 19-Jun-2020 08:53:45

2K+ Views

Use the StartWith() method in C# to check for URL in a String.Let us say our input string is −string input = "https://example.com/new.html";Now we need to check for www or non-www link. For this, use the if statement in C# −if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) { }ExampleYou can try to run the following code to check for URL in a string.Live Demousing System; class Demo {    static void Main() {       string input = "https://example.com/new.html";       // See if input matches one of these starts.       if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) {       ... Read More

C# Multiple Local Variable Declarations

karthikeya Boyini
Updated on 19-Jun-2020 08:54:19

771 Views

In C#, you can use the comma to declare more than one local variable in a statement. The following displays the same −int a = 20, b = 70, c = 40, d = 90;ExampleLet us see an example in which we are declaring multiple local variables. Below four variable is declared and initialized in the same statement.Live Demousing System; class Demo {    static void Main() {       int a = 20, b = 70, c = 40, d = 90;       Console.WriteLine("{0} {1} {2} {3}", a, b, c, d);    } }Output20 70 40 90

C# Language advantages and applications

Samual Sam
Updated on 19-Jun-2020 08:54:56

5K+ Views

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different computer platforms and architectures.Advantages of C#Object-Oriented LanguageAutomatic Garbage CollectionCross PlatformBackward CompatibilityBetter Integrity and InteroperabilityApplications of C#Games using UnityWeb Applications Client-Server ApplicationsWindows Applications Applications that run on desktopsWeb Services ApplicationsConsole ApplicationsClass Libraries

C# Generics vs C++ Templates

karthikeya Boyini
Updated on 19-Jun-2020 08:56:11

600 Views

C# Generics and C++ Templates provide support for parameterized types. The following are the differences −FlexibilityC++ Templates are more flexible than C# GenericsExplicit specializationExplicit specialization is not supported by C#Type ParameterThe type parameter cannot be used as the base class for the generic type in C#C# does not allow type parameters to have default types.Run-TimeThe C++ template has a compile-time modal, whereas C# Generics is both compile and run-time. Generics have run-time support.Non-type template parametersC#Templates will not allow non-type template parameters.Partial SpecializationC# does not even support partial specialization.

C# factorial

Samual Sam
Updated on 19-Jun-2020 08:57:13

4K+ Views

To calculate factorial in C#, you can use while loop and loop through until the number is not equal to 1.Here n is the value for which you want the factorial −int res = 1; while (n != 1) {    res = res * n;    n = n - 1; }Above, let’s say we want 5! (5 factorial)For that, n=5, Loop Iteration 1 −n=5 res = res*n i.e res =5;Loop Iteration 2 −n=4 res = res*n i.e. res = 5*4 = 20Loop Iteration 3 −n=3 res = res*n i.e. res = 20*3 = 60ExampleIn this way, all the ... Read More

C# Example for MultiLevel Inheritance

Samual Sam
Updated on 19-Jun-2020 08:58:22

5K+ Views

Multilevel Inheritance occurs when a derived class is formed from another derived class.Grandfather, father, and son are the perfect example to represent Multilevel Inheritance in C# −ExampleThe following is an example stating the usage of multilevel inheritance in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class Son : Father {       public void DisplayTwo() {          Console.WriteLine("Son.. ");       }       static void Main(string[] args) {          Son s = new Son();          s.Display();          s.DisplayOne(); ... Read More

C# Example for Single Inheritance

karthikeya Boyini
Updated on 19-Jun-2020 08:58:59

4K+ Views

The following is an example of Single Inheritance in C#. In the example, the base class is Father and declared like the following code snippet −class Father {    public void Display() {       Console.WriteLine("Display");    } }Our derived class is Son and is declared below −class Son : Father {    public void DisplayOne() {       Console.WriteLine("DisplayOne");    } }ExampleThe following is the complete example to implement Single Inheritance in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyAplication {    class Demo {       static void Main(string[] args) {   ... Read More

C# Bitwise and Bit Shift Operators

Samual Sam
Updated on 19-Jun-2020 09:00:12

3K+ Views

Bitwise operator works on bits and performs bit by bit operation.The Bitwise operators supported by C# are listed in the following table. Assume variable A holds 60 and variable B holds 13 −OperatorDescriptionExample&Bitwise AND Operator copies a bit to the result if it exists in both operands.(A & B) = 12, which is 0000 1100|Bitwise OR Operator copies a bit if it exists in either operand.(A | B) = 61, which is 0011 1101^Bitwise XOR Operator copies the bit if it is set in one operand but not both.(A ^ B) = 49, which is 0011 0001~Bitwise One's Complement Operator ... Read More

Advertisements