-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic1.cs
More file actions
150 lines (123 loc) · 3.58 KB
/
basic1.cs
File metadata and controls
150 lines (123 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
namespace basic
{
class myclass
{
string nm = "myclass";
internal void printname(string strnm)
{
Console.WriteLine(strnm);
Console.WriteLine(nm);
}
internal int num()
{
Random rand = new Random();
return rand.Next();
}
}
class myclass2
{
private string strname;
internal myclass2(string strnam)
{
strname = strnam;
}
internal void printnm()
{
Console.WriteLine(strname);
}
}
class Program
{
static void Main(string[] args)
{
myclass obj = new myclass();
//obj.nm = "xyz";
obj.printname("avishek");
int n = obj.num();
Console.WriteLine(n);
myclass2 obj2 = new myclass2("diamond");
obj2.printnm();
char ch = 'D';
//int i = 0;
string strnm = "NAME";
//Console.WriteLine(ch);
Console.WriteLine(strnm.Length);
Console.WriteLine(strnm.ToLower());
Console.WriteLine(strnm.IndexOf('A'));
Console.WriteLine(strnm[2]);
Console.WriteLine(strnm.Substring(0, 2));
for(int i=0;i<strnm.Length;i++)
{
Console.WriteLine(strnm[i]);
}
int j = 7;
while(j<5)
{
Console.WriteLine(j);
j += 2;
}
do
{
Console.WriteLine(j + "inside do while");
} while (j < 5);
bool istrue = true;
int[] arrnm = new int[5];
arrnm[0] = 100;
arrnm[1] = 200;
for(int i=0;i<arrnm.Length;i++)
{
arrnm[i] = i;
Console.WriteLine(arrnm[i]);
}
int[] arr2 = { 1, 2, 3, 4, 5, 6, 7,8 };
for(int i=0;i<arr2.Length; i++)
{
Console.WriteLine(arr2[i]);
}
foreach(int itm in arr2)
{
Console.WriteLine(itm);
}
string[] str = { "abc", "xyz", "diamond" };
for(int i=0;i<str.Length;i++)
{
Console.WriteLine(str[i]);
}
foreach(string s in str)
{
Console.WriteLine(s);
}
double d = Math.Pow(2, 3);
double d2 = Math.Sqrt(2);
Console.WriteLine("enter a number");
int num = int.Parse(Console.ReadLine());
if(num<0)
{
Console.WriteLine("negative number");
}
else if(num>100)
{
Console.WriteLine("more than 100");
}
else
{
Console.WriteLine("positive number");
}
Console.WriteLine("Enter the month number");
int mon = int.Parse(Console.ReadLine());
switch(mon)
{
case 1:
Console.WriteLine("January");
break;
case 2:
Console.WriteLine("feb");
break;
default:
Console.WriteLine("march and above");
break;
}
}
}
}