×

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 2

C# Strings Aptitude Questions | Set 2: 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;
	String STR3;

	STR2 = STR1;
	STR3 = String.Copy(STR1);

	STR1.Insert(1, "XYZ");

	Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
  1. AXYZBC ABC ABC
  2. ABC ABC ABC
  3. AXYZBC AXYZBC ABC
  4. Syntax Error

2) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String STR1 = "ABC";
	String STR2;
	String STR3;

	STR2 = STR1;
	STR3 = String.Copy(STR1);

	STR1 = STR1.Insert(1, "XYZ");

	Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
  1. AXYZBC ABC ABC
  2. ABC ABC ABC
  3. AXYZBC AXYZBC ABC
  4. Syntax Error

3) If we will access a character from a string that is outside the string size, then which exception will generate?
  1. ArrayIndexOutOfBoundExcepion
  2. IndexOutOfRangeException
  3. OutOfBoundException
  4. StringException

4) What is the correct way to get a character from string in C#.NET?
static void Main(string[] args)
{
	String s1 = "ABC";
	string s2 = "ABC";

	if(s1==s2)
		Console.WriteLine("S1 and S2 are equal");
	else
		Console.WriteLine("S1 and S2 are not equal");
}
  1. String str="sample"; char ch = str[0];
  2. String str="sample"; char ch = str.getChar(0);
  3. String str="sample"; char ch = str.CharAt(0);
  4. String str="sample"; char ch = str.Char(0);

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "SAMPLE";

	char ch = str[6];

	Console.WriteLine(ch);
}
  1. E
  2. 'E'
  3. Runtime Exception
  4. Syntax Error



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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