Archive

Posts Tagged ‘C#’

Data Types:Primitive and Non Primitive


Data Types are 2 types based on Data.

1. Primitive data types
2. Non Primitive data types

Primitive data types: Are predefined types of data, which are supported by the programming language.
Ex: integer, character, bool, float and string
These types are defined by programming language.

Non-primitive data types are not defined by the programming language, but are instead created by the programmer.They are sometimes called “reference variables,” or “object references,” since they reference a memory location, which stores the data

These are nothing but “Objects”.
Objects can contain any type of data.

FizzBuzz Logic


public void DoFizzBuzz()
{
for (int i = 1; i <= 100; i++)
{
bool fizz = i % 3 == 0;
bool buzz = i % 5 == 0;
if (fizz && buzz)
Console.WriteLine (“FizzBuzz”);
else if (fizz)
Console.WriteLine (“Fizz”);
else if (buzz)
Console.WriteLine (“Buzz”);
else
Console.WriteLine (i);
}
}
Or

using System;
class FizzBuzz {
static void Main() {
for (int n = 1; n <= 100; n ++) {
if (n % 15 == 0) {
Console.WriteLine(“FizzBuzz”);
}
else if (n % 3 == 0) {
Console.WriteLine(“Fizz”);
}
else if (n % 5 == 0) {
Console.WriteLine(“Buzz”);
}
else {
Console.WriteLine(n);
}
}
}
}

Categories: C# Tags: ,

Visual C# .NET Programming

Asp.Net Samples