Custom Search

Monday 21 September 2015

C#: Different Ways to Write Text on Console: Concatenation, Placeholder Syntax



In C sharp we have two ways in which we can write text on the console. The first method is using string Concatenation which is explained below.

Concatenation
In this we are plus symbol to concatenate two strings together.

Console.WriteLine("Please enter your name");

string Username: Console.ReadLine();

Console.WriteLine("Hello " + Username);


Placeholder Syntax
This method is most widely used as its more flexible, you can set the value in the placeholders which will display your text according, for example I want to Write a code where in I want whenever the user login to their account the system should display

Welcome First name Last name

Console.WriteLine("Enter your first name");

string FirstName: Console.ReadLine();

Console.WriteLine("Enter your LastName");

string LastName: Console.ReadLine();

Console.WriteLine("Hello {0},{1}", FirstName, LastName);

In this we can swap the value of 0 and 1 and the text will be displayed accordingly

Thursday 17 September 2015

C#: How to Print message on console, C Sharp basic Program

Basic Structure of C Sharp
In every programming language their is actually a way to write text on the console window or you can say may be the syntax to write the same.

For example
using System
public static void main()
{
Console.WriteLine("Welcome to C- Prog. Concepts");
}

using System
This line tells us that we are going to use the code which is present insude the system namespace.

Its helps as a building block and combines all the data inside your code as a collection os classes, interface struts, enums etc

If we don't use system namespace the program will not interpret what is actually the console in the below line is.

WriteLine("")
In this the text in double quotes will be displayed in the console and this is what the user will see in the screen. It is similar to printf in C++, echo in unix etc.

Tuesday 15 September 2015

Unix Script to Print Pyramid of Stars


Unix Script for Printing Stars
Here is the simple script in Unix / Linus to print the stars in the form of Pyramid as shown below.
We have used for loop for the same as we use it in C/C++. The read command in the same helps to save the users input for further use. The echo command helps the user to display the data on the screen.

 Print the pyramid of stars
      #!/bin/bash
      echo "pyramid size (1 to 100): "
      read n
      for ( (i=1;i<=n;i++ ) )
      do
for ( (k=i;k<=n;k++ ) )
do
  echo -ne "  "
done
for ( (j=1;j<=i;j++) )
do
  echo -ne "*"
done
for ( (z=1;z<i;z++) )
do
  echo -ne "*"
     done

Laptops