
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to print all sublists of a list
Firstly, create a list −
List list = new List();
The string here is “xyz” for which we will find the sublists. While looping we will declare another list, that would generate sublists on every true iteration −
for (int i = 1; i < str.Length; i++) { list.Add(str[i - 1].ToString()); List newlist = new List(); for (int j = 0; j < list.Count; j++) { string list2 = list[j] + str[i]; newlist.Add(list2); } list.AddRange(newlist); }
The following is the complete code −
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { string str = "xyz"; List list = new List(); for (int i = 1; i < str.Length; i++) { list.Add(str[i - 1].ToString()); List newlist = new List(); for (int j = 0; j < list.Count; j++) { string list2 = list[j] + str[i]; newlist.Add(list2); } list.AddRange(newlist); } list.Add(str[str.Length - 1].ToString()); list.Sort(); Console.WriteLine(string.Join(Environment.NewLine, list)); } } }
Output
x xy xyz xz y yz z
- Related Articles
- Python program to print all sublists of a list.
- Program to find sum of the sum of all contiguous sublists in Python
- Program to find sum of medians of all odd length sublists in C++
- Program to find number of sublists with sum k in a binary list in Python
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- Java program to print duplicates from a list of integers
- C# program to print duplicates from a list of integers
- Python program to print duplicates from a list of integers?
- Java Program to Print all unique words of a String
- Python Program to print all permutations of a given string
- C Program to print all permutations of a given string
- Python Program to Print Middle most Node of a Linked List
- Program to print all substrings of a given string in C++
- Python Program to print unique values from a list
- Python program to print even numbers in a list

Advertisements