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
Programming Articles - Page 3158 of 3363
899 Views
The C# static class cannot be instantiated and can only have only static members. The static class in C# is sealed and cannot contain instance constructors.The following is an example with static class and static members −Example Live Demousing System; public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} } class Program { public static void Main(string[] args) { Console.WriteLine("PI: "+Demo.PI); Console.WriteLine("Square: " + Demo.calc(3)); } }OutputPI: 3.14 Square: 9Above, the static class is −public static class Demo { ... Read More
2K+ Views
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. 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.The following are the major features of C# −Following is the list of few important features of C# −Boolean ConditionsAutomatic Garbage CollectionStandard LibraryAssembly VersioningProperties and EventsDelegates and Events ManagementEasy-to-use GenericsIndexersConditional CompilationSimple MultithreadingLINQ and Lambda ExpressionsIntegration with Windows
1K+ Views
IS operatorThe "is" operator in C# checks whether the run-time type of an object is compatible with a given type or not.The following is the syntax −expr is typeHere, expr is the expressiontype is the name of the typeThe following is an example showing the usage of is operator in C# &minis;Example Live Demousing System; class One { } class Two { } public class Demo { public static void Test(object obj) { One x; Two y; if (obj is One) { Console.WriteLine("Class One"); ... Read More
3K+ Views
Use the Any method to find whether the list is empty or not.Set the list −var subjects = new List(); subjects.Add("Maths"); subjects.Add("Java"); subjects.Add("English"); subjects.Add("Science"); subjects.Add("Physics"); subjects.Add("Chemistry");Now set the following condition to check whether the list is empty or not −bool isEmpty = !subjects.Any(); if(isEmpty) { Console.WriteLine("Empty"); }else { Console.WriteLine("List is not empty"); }The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main(string[] args) { var subjects = new List(); subjects.Add("Maths"); ... Read More
698 Views
Firstly, create a list −List list = new List();The string here is “xyz” for which we will find the sublists. While looping we will declare another list, that would generate sublists on every true iteration −for (int i = 1; i < str.Length; i++) { list.Add(str[i - 1].ToString()); List newlist = new List(); for (int j = 0; j < list.Count; j++) { string list2 = list[j] + str[i]; newlist.Add(list2); } list.AddRange(newlist); }The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo ... Read More
3K+ Views
To assign same value to multiple variables in a single line, use the = operator −val1 = val2 = 20;The above statement assigns 20 to the variables val1 and val2 as shown in the following code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { int val1, val2; val1 = val2 = 20; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); } } }OutputValue1 = 20 Value2 = 20
6K+ Views
To print the numbers divisible by 3 and 5, use the && operator and check two conditions −f (num % 3 == 0 && num % 5 == 0) {}If the above condition is true, that would mean the number is divisible by 3 as well as 5.The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { int num; num = 15; Console.WriteLine("Number: "+num); // checking if the number is divisible by 3 and 5 if (num % 3 == 0 && num % 5 == 0) { Console.WriteLine("Divisible by 3 and 5"); } else { Console.WriteLine("Not divisible by 3 and 5"); } Console.ReadLine(); } } }OutputNumber: 15 Divisible by 3 and 5
2K+ Views
Firstly create the two lists −List list1 = new List() {40, 20, 60, 3, 55}; List list2 = new List() {20, 70, 55, 80};To find the common elements, use the Intersect −list1.Intersect(list2)The following is the complete code to find the common elements between the two lists −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { List list1 = new List() {40, 20, 60, 3, 55}; List list2 = new List() {20, 70, 55, 80}; Console.WriteLine("Common elements:"); foreach(int value in list1.Intersect(list2)) Console.WriteLine(value); } } }OutputCommon elements: 20 55
909 Views
The comments that spread more than one line is called multi-line comments −/* The following is a multi-line Comment In C# /*The /*...*/ is ignored by the compiler and it is put to add comments in the program.The following is a sample C# program showing how to add MULTI-line comments −using System; namespace Demo { class Program { static void Main(string[] args) { /* The following is a multi-line Comment In C# /* // printing Console.WriteLine("Hello World"); Console.ReadKey(); } } }