Found 2587 Articles for Csharp

Difference between namespace in C# and packages in Java

Samual Sam
Updated on 23-Jun-2020 09:41:31

3K+ Views

Packages in JavaPackages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.Define a Package as −package package_name;Restrict the access of classes (or class members) to the classes within the same package, but in C# with namespaces you cannot achieve this.Namespace in C#A namespace is designed for providing a way ... Read More

Comparison between C# and .NET Framework

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

587 Views

C# is a programming language and .NET framework is a software framework developed by Microsoft. .NET has Common Language Runtime (CLR), which is a virtual component of .NET framework. And framework is a large class of library. .NET not only has C#, but through it, you can work with VB, F#, etc. Programs written for .NET Framework execute in Common Language Runtime. .NET Framework supports development in C#. C# is a part of .NET and has the following features − Boolean Conditions Automatic Garbage Collection Standard Library Assembly Versioning Properties and Events Delegates and Events Management

C# program to Count words in a given string

karthikeya Boyini
Updated on 23-Jun-2020 09:42:41

756 Views

Let’s say we want to count the number of words in the following string −str1 = "Hello World!";Now you need to loop though till string length and increment the variable count on finding “ “, , \t as shown below −if(str1[a]==' ' || str1[a]=='' || str1[a]=='\t') {    count++; }You can try to run the following code to count words in a given string in C#.Example Live Demousing System; public class Demo {    public static void Main() {       string str1;       int a, count;       str1 = "Hello World!";       a = 0;       count = 1;       while (a

C# Program to display the Factors of the Entered Number

Chandu yadav
Updated on 23-Jun-2020 09:28:42

374 Views

Firstly, let us enter the number.Console.WriteLine("Enter a Number"); n = int.Parse(Console.ReadLine());Now loop through and find the mod of the entered number with i = 1 that increments after every iteration. If its 0, then print it, since it would be our factor.for (i= 1; i

Comparing dates using C#

Samual Sam
Updated on 23-Jun-2020 09:29:16

308 Views

To compare dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C#.Date 1DateTime date1 = new DateTime(2018, 07, 20); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 07, 25); Console.WriteLine("Date 2 : {0}", date2);Now let us compare both the dates in C#. The following is an example to compare dates in C#.Example Live Demousing System; namespace Program {    class Demo {       static int Main() {          DateTime date1 = new DateTime(2018, 07, 20);         ... Read More

Enum with Customized Value in C#

George John
Updated on 23-Jun-2020 09:29:44

2K+ Views

Enum is Enumeration to store a set of named constants like year, product, month, season, etc.The default value of Enum constants starts from 0 and increments. It has fixed set of constants and can be traversed easily. However you can still change the start index and customize it with the value of your choice.In the following example, I have set the customized value to be 20 instead of the default 0.Example Live Demousing System; public class Demo {    public enum Vehicle { Car =20, Motorcycle, Bus, Truck }    public static void Main() {       int a = ... Read More

Division Operator in C#

Samual Sam
Updated on 23-Jun-2020 09:32:12

7K+ Views

Division operator is used in C# to divide numerator by denominator, for example 9/ 3The division operator comes under Arithmetic Operators in C#. Let us see a complete example to learn how to implement Arithmetic operators in C#, wherein we will see how to work with division operator.result = num1 / num2; Console.WriteLine("Division: Value is {0}", result);Above we have used division operator on num1 and num2.The following is the complete example.Example Live Demousing System; namespace Sample {    class Demo {       static void Main(string[] args) {          int num1 = 50;         ... Read More

Differences between C and C#

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

2K+ Views

C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972. C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. The following are the differences between C and C#. Language C language is a structured programming language, whereas C# is an object-orinted language. Memory Management C has manual memory management, whereas memory management is handled automatically in C#. Garbage Collection C do not have ... Read More

Difference between IComparable and IComparer Interface in C#

karthikeya Boyini
Updated on 23-Jun-2020 09:33:14

2K+ Views

IComparable Interface in C#Use the IComparable Interface in C# to sort elements. It is also used to compare the current instance with another object of same type.It provides you with a method of comparing two objects of a particular type. Remember, while implementing the IComparable interface, CompareTo() method should also be implemented.Let us see an example −int IComparable.CompareTo(object ob) {    Vehicle v=(Vehicle)ob;    return String.Compare(this.make, v.make); }IComparer interface in C#The IComparer interface is used to sort elements that compare two objects and provides additional comparison method.Exampleprivate class sortYearAscendingHelper : IComparer {    int IComparer.Compare(object ob1, object ob2) {   ... Read More

What is the IsReadOnly property of Hashtable class in C#?

Chandu yadav
Updated on 23-Jun-2020 09:34:34

131 Views

The IsReadOnly property of Hashtable class is used to get a value indicating whether the Hashtable is read-only.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Hashtable ht = new Hashtable();          ht.Add("One", "Amit");          ht.Add("Two", "Aman");          ht.Add("Three", "Raman");          Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);          Console.ReadKey();       }    } }OutputIsReadOnly = FalseAbove we have set a Hashtable with three elements.ht.Add("One", "Amit"); ht.Add("Two", "Aman"); ht.Add("Three", "Raman");After that, we have checked using the IsReadOnly property.Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);

Advertisements