karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 62 of 143

What is method hiding in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

Method hiding is also known as shadowing. The method of the parent class is available to the child class without using the override keyword in shadowing. The child class has its own version of the same function.Use the new keyword to perform shadowing.Let us see an example.Exampleusing System; using System.Collections.Generic; class Demo {    public class Parent {       public string GetInfo () {          return "This is Parent Class!";       }    }    public class Child : Parent {       public new string GetInfo() {          return "This is Child Class!";       }    }    static void Main(String[] args) {       Child child = new Child();       Console.WriteLine(child. GetInfo());    } }OutputThis is Child Class!

Read More

C# Program to check whether a directory exists or not

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 324 Views

Use the Directory. Exists method to check whether a directory exists or not.Let’s say you need to check whether the following directory exists or not −C:\AmitFor that, use the Exists() method −if (Directory.Exists("C:\Amit")) {    Console.WriteLine("Directory Amit Exist!"); }The following is the complete code −Exampleusing System.IO; using System; public class Program {    public static void Main() {       if (Directory.Exists("C:\Amit")) {          Console.WriteLine("Directory Amit Exist!");       } else {       Console.WriteLine("Directory Amit does not exist!");       }    } }OutputDirectory Amit does not exist!

Read More

C# program to count the number of words in a string

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 8K+ Views

Let us first declare the string −string str = "Hello World!";Now loop through the complete string and find the whitespace or tab or newline character −while (a

Read More

C# program to convert binary string to Integer

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Use the Convert.ToInt32 class to fulfill your purpose of converting a binary string to an integer.Let’s say our binary string is −string str = "1001";Now each char is parsed −try {    //Parse each char of the passed string    val = Int32.Parse(str1[i].ToString());    if (val == 1)       result += (int) Math.Pow(2, str1.Length - 1 - i);    else if (val > 1)       throw new Exception("Invalid!"); } catch {    throw new Exception("Invalid!"); }Check the above for each character in the passed string i.e. “100” using a for a loop. Find the length of ...

Read More

What is the difference between a mutable and immutable string in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

Mutable stringStringBuilder is a mutable string in C#. With StringBuilder, you can expand the number of characters in the string. The string cannot be changed once it is created, but StringBuilder can be expanded. It does not create a new object in the memory.Set StringBuilder −StringBuilder str = new StringBuilder();Let us see an example to learn how to work with StringBuilder in C# −Exampleusing System; using System.Text; public class Program {    public static void Main() {       StringBuilder str = new StringBuilder("Web World!!", 30);       str.Replace("World", "Arena");       Console.WriteLine(str);    } ...

Read More

C# Program to get the last write time of a file

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To get the last write time of a file in C#, use the LastWriteTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("amit.txt"); DateTime dt = file.CreationTime; dt = file.LastWriteTime;Let us see the complete code −Exampleusing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("amit.txt")) {          sw.WriteLine("Welcome!");       }       FileInfo file = new FileInfo("amit.txt");       // file creation time       DateTime dt = file.CreationTime; ...

Read More

C# Program to Convert Character case

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 614 Views

Let’s say your string is −str = "AMIT";To convert the above uppercase string in lowercase, use the ToLower() method −Console.WriteLine("Converted to LowerCase : {0}", str.ToLower());ExampleThe following is the code in C# to convert character case.using System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          string str;          str = "AMIT";          Console.WriteLine("UpperCase : {0}", str);          // convert to lowercase          Console.WriteLine("Converted to LowerCase : {0}", str.ToLower());          Console.ReadLine();       }    } }OutputUpperCase : AMIT Converted to LowerCase : amit

Read More

Get the creation time of a file in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To get the creation time of a file in C#, use the CreationTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime;Let us see the complete code −Exampleusing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("qa.txt")) {          sw.WriteLine("Questions and Answers!");       }       FileInfo file = new FileInfo("qa.txt");       // file creation time       DateTime dt = file.CreationTime;       Console.WriteLine(dt);    } }Output9/5/2018 5:20:03 AM

Read More

Literal number suffixes in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 530 Views

To specify number types, use suffixes in C#. Literal number suffixes are numeric suffixes.For example, for long type −// long suffix long val1 = 29345L;For double type −// double suffix double val2 = 297.325D; Console.WriteLine(val2);Let us see more examples −Exampleusing System.IO; using System; public class Program {    public static void Main() {       // long suffix       long val1 = 29345L;       Console.WriteLine(val1);       // decimal suffix       decimal val5 = 3245.5678M;       Console.WriteLine(val5);       // double suffix       double val2 = 297.325D;       Console.WriteLine(val2);       // float suffix       float val3 = 250.35F;       Console.WriteLine(val3);       // unsigned suffix       uint val4 = 3456U;       Console.WriteLine(val4);    } }Output29345 3245.5678 297.325 250.35 3456

Read More

C# Program to convert first character uppercase in a sentence

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 543 Views

Let us say the following is your string −String str = "Welcome to our website!";Create a char array of the string included above using the ToCharArray() method:char []ch = str.ToCharArray();To convert the first character to uppercase −if (ch[i] >= 'a' && ch[i] = 'a' && val[i] = 'A' && val[i]

Read More
Showing 611–620 of 1,421 articles
« Prev 1 60 61 62 63 64 143 Next »
Advertisements