Infinity provides different options to add code blocks in the documentation. The code blocks also provides syntax highlighting facility based on the code language selected.
Option 1: Simple Code Block
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Iterators
{
public static class ForeachExamples
{
public static void ExampleOne()
{
var collection = new List<string>
{
"Hello",
"World",
"Iterators",
"are",
"awesome"
};
foreach (var item in collection)
{
Console.WriteLine(item.ToString());
}
}
}
}
Code Blocks in Horizontal Tabs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Iterators
{
public static class ForeachExamples
{
public static void ExampleOne()
{
var collection = new List<string>
{
"Hello",
"World",
"Iterators",
"are",
"awesome"
};
foreach (var item in collection)
{
Console.WriteLine(item.ToString());
}
}
}
}
import java.util.Scanner;
public class DiamondCharacterPattern {
public static void main(String[] args) {
char[] alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int alphabet _number = 0;
String[] diamond = new String[26]; // array of strings
System.out.print("Enter a Character between A to Z : ");
Scanner reader = new Scanner(System.in);
try {
char user_ alphabet = reader.next("[A-Z]").charAt(0);
// search for letter number in the array letter
for (int i = 0; i < alphabet.length; i++) {
if (letter[i] == user_ alphabet) {
alphabet _number = i;
break;
}
}
//construct diamond
for (int i = 0; i <= alphabet _number; i++) {
diamond[i] = "";
//add initial spaces
for (int j = 0; j < alphabet _number - i; j++) {
diamond[i] += " ";
}
// add alphabet
diamond[i] += alphabet
//add space between letters
if (alphabet[i] != 'A') {
for (int j = 0; j < 2 * i - 1; j++) {
diamond[i] += " ";
}
// add alphabet
diamond[i] += alphabet[i];
}
// Draw the first part of the diamond
System.out.println(diamond[i]);
}
for (int i = alphabet _number - 1; i >= 0; i--) {
// Draw the second part of the diamond
// prints the diamondArray in the reverse order
System.out.println(diamond[i]);
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
reader.close();
}
}
}
<?php
// PHP program to prepend a string
// Function to prepend a string
function prepend_string ($str1, $str2){
// Using concatenation operator (.)
$res = $str1 . $str2;
// Returning the result
return $res;
}
// Given string
$str1 = "Geeksforgeeks";
$str2 = "Example";
// Function Call
$str = prepend_string ($str1, $str2);
// Printing the result
echo $str;
?>