Found 34488 Articles for Programming

C# Multiple Local Variable Declarations

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

611 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

4K+ 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

376 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

2K+ 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

4K+ 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

3K+ 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

C# program to check if string is panagram or not

Samual Sam
Updated on 19-Jun-2020 08:28:49

1K+ Views

A pangram has all the 26 letters of an alphabet.Below, we have entered a string, and will check whether it is a pangram or not −string str = "The quick brown fox jumps over the lazy dog";Now, check using the ToLower(), isLetter() and Count() functions that the string has all the 26 letters of not since pangram has all the 26 letters of an alphabet.ExampleYou can try to run the following code to check whether a string is pangram or not.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class Program {       ... Read More

C# program to check if a Substring is present in a Given String

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

462 Views

Use the contains() method in C# to check if a substring is in a given string.Let us say the string is −UnitedWithin the string, you need to find the substring “Uni”. For that, use the contains method and use it like the following code snippet −res = str1.Contains(str2);ExampleYou can try to run the following code to find a substring in a string.Live Demousing System; public class Demo {    public static void Main() {       string str1 = "United", str2 = "Uni";       bool res;       res = str1.Contains(str2);       if (res) ... Read More

C# Example for Hierarchical Inheritance

Samual Sam
Updated on 19-Jun-2020 08:32:41

3K+ Views

More than one class is inherited from the base class in Hierarchical Inheritance.In the example, our base class is Father −class Father {    public void display() {       Console.WriteLine("Display...");    } }It has Son and Daughter as the derived class. Let us how to add a derived class in Inheritance −class Son : Father {    public void displayOne() {       Console.WriteLine("Display One");    } }ExampleThe following the complete example of implementing Hierarchical Inheritance in C# −using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Inheritance {    class Test {       static ... Read More

Advertisements