0% found this document useful (0 votes)
40 views4 pages

Practical 10: NAME - Aman Garg ROLL NO - 1/17/FET/BCC/015

The document describes three C# programs written by Aman Garg to demonstrate mutable strings, constructor overloading, and properties. The first program performs methods like Append, Insert, Remove, and Replace on a StringBuilder. The second program shows default and parameterized constructors. The third program defines a Name property with get and set accessors to illustrate properties.

Uploaded by

aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Practical 10: NAME - Aman Garg ROLL NO - 1/17/FET/BCC/015

The document describes three C# programs written by Aman Garg to demonstrate mutable strings, constructor overloading, and properties. The first program performs methods like Append, Insert, Remove, and Replace on a StringBuilder. The second program shows default and parameterized constructors. The third program defines a Name property with get and set accessors to illustrate properties.

Uploaded by

aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL 10

NAME – Aman Garg


ROLL NO – 1/17/FET/BCC/015
AIM: WAP TO PERFORM VARIOUS METHODS ON MUTABLE STRINGS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication193
{
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder("This book");
string s = "is completed";
Console.WriteLine("Length of the stringbuilder {0} is {1}", sb, sb.Length);
Console.WriteLine("Capacity of the stringbuilder {0} is {1}", sb,
sb.Capacity);
Console.WriteLine("StringBuilder before appending is {0}", sb);
Console.WriteLine("StringBuilder after appending {0} is {1}", s,
sb.Append(s));
Console.WriteLine("stringbuilder after inserting now is {0}", sb.Insert(11,
"now"));
Console.WriteLine("StringBuilder after removing 'is' is {0}", sb.Remove(8,
3));
Console.WriteLine("Stringbuilder replacing all 'o' with 'x' is {0}",
sb.Replace('o', 'x'));
Console.ReadLine();
}
}
}

S
PRACTICAL 11
NAME – Aman Garg
ROLL NO – 1/17/FET/BCC/015
AIM: WAP TO SHOW CONSTRUCTOR OVERLOADING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication193
{
class GameScore
{
string user;
int age;
//Default Constructor
public GameScore()
{
user = "Steven";
age = 28;
Console.WriteLine("Previous User {0} and he was {1} year old", user, age);
}

//Parameterized Constructor
public GameScore(string name, int age1)
{
user = name;
age = age1;
Console.WriteLine("Current User {0} and he is {1} year old", user, age);
}
}

class Program
{
static void Main(string[] args)
{
GameScore gs = new GameScore(); //Default Constructor Called
GameScore gs1 = new GameScore("Clark", 35); //Overloaded Constructor.
Console.ReadLine();
}
}
}
OUTPUT
PRACTICAL 12
NAME – Aman Garg
ROLL NO – 1/17/FET/BCC/015
AIM: WAP TO IMPLEMENT THE PROPERTIES IN C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication193
{
// C# program to illustrate the
// read and wirte property
public class Student
{
// Declare name field
private string name = "GeeksforGeeks";
// Declare name property
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
class TestStudent
{
// Main Method
public static void Main(string[] args)
{
Student s = new Student();

// calls set accessor of the property Name,


// and pass "GFG" as value of the
// standard field 'value'.
s.Name = "GFG";
// displays GFG, Calls the get accessor
// of the property Name.
Console.WriteLine("Name: " + s.Name);
Console.ReadLine();
}
}

You might also like