The main purpose of "Dot Net Labs" provide the dot net program. You can learn dot net, .Net Core, C#, SQL, Linq step-by-step.

Saturday, 30 May 2015

SIZEOF Keyword Example : It shows the size of Data types


We will learn about sizeof() with the help of the example. Here sizeof() is an operator in c#. It used to obtain the size of a data type in bytes and works only on compile-time. It does not work with the variable and instance.

Example:

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

namespace DataTypesDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("The size of short is {0} bytes.",sizeof(short));
Console.WriteLine("The size of int is {0} bytes.", sizeof(int));
Console.WriteLine("The size of long is {0} bytes.", sizeof(long));
Console.WriteLine("The size of float is {0} bytes.", sizeof(float));
Console.WriteLine("The size of double is {0} bytes.", sizeof(double));
Console.WriteLine("The size of char is {0} bytes.", sizeof(char));

Console.ReadLine();
}
}
}




Command Line Arguments Demo : Enter the Arguments on execution time


Step 1: Enter the below program in “Notepad”

using System;
class CommandLineDemo
{
static void Main(string []args)
{
Console.WriteLine("Welcome to CommandLine Arguments Demo");
Console.WriteLine("First argument is :"+ args[0]);
Console.WriteLine("Second argument is :"+ args[1]);
Console.ReadLine();
}
}

Step 2 : Save with extention “ <file_name>.cs”

Step 3 : Open Visual Studio Command Prompt


Step 4 : Open command prompt as below




Step 5 : Enter the file location by command “ cd ” and for exit command “ cd.. “


Step 6 : Compile to file with “ csc <file_name>.cs “



Step : 7 Execute program with “ <file name>.exe dot_net c_csharp “



Wednesday, 27 May 2015

How to save C# program in Notepad



To save a C# program using Notepad, you can follow these steps:

Open Notepad

Open the Notepad application on your computer. You can usually find it by searching for "Notepad" in the Start menu.

Write your C# program

In Notepad, write or copy-paste your C# program code into the editor.

Save the file

To save the file, go to "File" in the menu bar and click on "Save" or use the keyboard shortcut Ctrl + S.

Choose a file name

In the Save dialog, choose a name for your C# program file. Make sure to give it a .cs extension to indicate that it's a C# source code file. For example, you can name it "MyProgram.cs".

Select a location

Choose a location on your computer where you want to save the file. It could be your desktop or a specific folder.

Save the file

Click on the "Save" button to save the C# program file with the chosen name and location.



Step 1 : File save with file extention " .cs "






Step 2 : Open developer command prompt for compiling





Step 3 : Find Location of saved file




Step 4 : To compile file on command with " csc <file_name>.cs "




Step 5 : To run and output command with " <file_name>.exe "


Popular Posts