Friday 15 April 2011

.net - Calling variables from different classes c# -



.net - Calling variables from different classes c# -

i'm trying write programme have 2 classes, , phone call 2 variables 1 got 2 errors saying " 'area.circle' not contain definition 'result1' " , " 'area.circle' not contain definition 'result2' ". how can solve problem?

using system; namespace area { class circle { public static void area() { console.writeline("enter radius of first circle: "); int r1 = convert.toint32(console.readline()); console.writeline("enter radius of sec circle: "); int r2 = convert.toint32(console.readline()); double pi = math.pi; double result1 = pi * r1 * r1; double result2 = pi * r2 * r2; console.writeline("the area of first circle {0}\nthe area of sec circle {1}\n", result1, result2); } } class minimum { static void main(string[] args) { circle.area(); circle 1 = new circle(); double min = math.min(circle.result1, circle.result2); console.writeline("min"); } } }

the problem defining result1 , result2 within scope of area() method. declare them @ class level, public , static, , accessible.

as method area() static variables have static in order accessed within it. accessing variables static other class though, should work.

c# .net class oop variables

No comments:

Post a Comment