public class test {
int wid;
int hei;
int len;
int vol;
void vol1(int hei, int len, int wid) {
vol = wid * hei * len;
}
}
class Prameterized {
static void main(String[] args) {
test obj = new test();
obj.hei = 1;
obj.len = 5;
obj.wid = 5;
obj.vol(3, 2, 1);
Console.WriteLine(obj.vol);
Console.ReadLine();
}
}
In C#, what will be the output of the following code?
class square {
public int width;
public int height;
public int length;
public int volume1;
public void volume() {
volume1 = width * height * length;
}
public void volume(int x) {
volume1 = x;
}
}
class Program {
static void Main(string[] args) {
square obj = new square();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(5);
Console.WriteLine(obj.volume1);
Console.ReadLine();
}
}
#define DEBUG
# undef DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13 {
class Program {
static void Main(string[] args) {#
if (DEBUG)
Console.WriteLine("DEBUG is described");#
elif(!DEBUG && MYTEST)
Console.WriteLine("MYTEST is described");#
elif(DEBUG && MYTEST)
Console.WriteLine("DEBUG and MYTEST are described");#
else
Console.WriteLine("DEBUG and MYTEST are not described");#
endif
Console.ReadLine();
}
}
}
using System;
using System.Collections;
class MyClass {
char chrs = 'X';
public IEnumerator GetEnumerator() {
for (int i = 20; i >= 0; --i) {
if (i == 10) yield
break;
yield
return (char)((chrs + i));
}
}
class Program {
static void Main(string[] args) {
MyClass mc = new MyClass();
foreach(char chrs in mc)
Console.Write(chrs + " ");
Console.WriteLine();
Console.ReadLine();
}
}
}
using System;
using System.Collections;
class MyClass {
char ch = 'B';
public IEnumerable MyItr(int end) {
for (int i = 0; i < end; i++)
yield
return (char)(ch + i);
}
public IEnumerable MyItr(int begin, int end) {
for (int i = begin; i < end; i++)
yield
return (char)(ch + i);
}
}
class Program {
static void Main(string[] args) {
MyClass bc = new MyClass();
Console.WriteLine("Iterate the first 7 letters:");
foreach(char ch in bc.MyItr(7))
Console.Write(ch + " ");
Console.WriteLine("n");
Console.WriteLine("Iterate letters from F to L:");
foreach(char ch in bc.MyItr(7, 12))
Console.Write(ch + " ");
Console.WriteLine();
Console.ReadLine();
}
}
using System;
using System.Collections;
class MyClass {
char ch = 'A';
int x = 4;
int y = 9;
int z = 6;
public IEnumerator GetEnumerator() {
for (int i = 0; i < 26; i++) {
if (i == x * y / z) yield
break;
yield
return (int)(ch + i);
}
}
}
class Program {
static void Main(string[] args) {
MyClass mc = new MyClass();
foreach(int ch in mc)
Console.Write(ch + " ");
Console.WriteLine();
Console.ReadLine();
}
}