×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# Strings Aptitude Questions and Answers | Set 4

C# Strings Aptitude Questions | Set 4: This section contains aptitude questions and answers on C# Strings.
Submitted by Nidhi, on April 05, 2020

1) What is the correct output of given code snippets?
static void Main(string[] args)
{
    String str1 = "ABC";
    String str2 = "ABC";

    if (str1.CompareTo(str2)==0)
        Console.WriteLine("Both are equal");
    else
        Console.WriteLine("Both are not equal");
}
  1. Both are equal
  2. Both are not equal
  3. Runtime Exception
  4. Syntax Error

2) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "This is a string";
	int i1 = 0;
	int i2 = 0;

	i1 = str.IndexOf('s');
	i2 = str.IndexOf('s', i1 + 1);

	Console.WriteLine(i1 + " " + i2);
}
  1. 3 6
  2. Syntax Error
  3. Runtime Exception
  4. 3 3

3) A string built using the StringBuilder class is Mutable?
  1. Yes
  2. No

4) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str1 = "Hello ";
	String str2 = "World!";
	String str3;

	str3 = str1.Concat(str2);

	Console.WriteLine(str3);
}
  1. Hello World!
  2. HelloWorld!
  3. Runtime Exception
  4. Syntax Error

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str1 = "Hello ";
	String str2 = "World!";
	String str3;

	str3 = str1+str2;

	Console.WriteLine(str3);
}
  1. Hello World!
  2. HelloWorld!
  3. Runtime Exception
  4. Syntax Error



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.