D**u 发帖数: 288 | 1 using System;
using System.Collections.Generic;
using System.Text;
namespace _000_TEST1
{
class A
{
public static int x = 5;
public int changex()
{
x = 4;
return x;
}
}
class Program
{
static void Main(string[] args)
{
var a = new A();
//Console.WriteLine(a.changex());
a.changex();
Console.WriteLine(A.x);
Console.ReadLine();
}
}
}
两个output 结果都是
4
请问这里大家的习惯是用Console.WriteLine(a.changex())呢?
还是
a.changex();
Console.WriteLine(A.x) 呢?
是不是如a.changex() 这种return 很少被用到,或者return 在大多数情况下都不常
用?
本人很努力的新手,谢谢啦! |
c*********e 发帖数: 16335 | 2 很少见到c#里有main的,你是从其它語言转c#的?
【在 D**u 的大作中提到】 : using System; : using System.Collections.Generic; : using System.Text; : namespace _000_TEST1 : { : class A : { : public static int x = 5; : public int changex() : {
|
D**u 发帖数: 288 | 3 之前用过一点c++,还有就只是SAS和R。
C#不都是先从Main()开始么,这样不是每个c#program里都有Main()?
还是说,大家都只用c#做form app所以没有Main()? |
n***e 发帖数: 723 | 4 winform也有。
不过wpf是隐藏起来了吧。
【在 D**u 的大作中提到】 : 之前用过一点c++,还有就只是SAS和R。 : C#不都是先从Main()开始么,这样不是每个c#program里都有Main()? : 还是说,大家都只用c#做form app所以没有Main()?
|
G***l 发帖数: 355 | 5 C#当然有main,不然程序从哪里开始?除了dll library不需要main,wpf也不需要。你
用C++不是每个program里都有main吗?
【在 D**u 的大作中提到】 : 之前用过一点c++,还有就只是SAS和R。 : C#不都是先从Main()开始么,这样不是每个c#program里都有Main()? : 还是说,大家都只用c#做form app所以没有Main()?
|
G***l 发帖数: 355 | 6 随便说点。
changex应该只用到了static field,应该定义成static method。定义成instance
method没有意义。
另外,改了x再return这样不是很好。调用过changex()之后再调用A.x取得x的值这样逻
辑会比较清晰。一个方法只做一件事。
【在 D**u 的大作中提到】 : using System; : using System.Collections.Generic; : using System.Text; : namespace _000_TEST1 : { : class A : { : public static int x = 5; : public int changex() : {
|
D**u 发帖数: 288 | 7 恩,多谢!
【在 G***l 的大作中提到】 : 随便说点。 : changex应该只用到了static field,应该定义成static method。定义成instance : method没有意义。 : 另外,改了x再return这样不是很好。调用过changex()之后再调用A.x取得x的值这样逻 : 辑会比较清晰。一个方法只做一件事。
|
a******g 发帖数: 13519 | 8 你个菜鸟!再也别来这版上混了,丢死人了。
【在 c*********e 的大作中提到】 : 很少见到c#里有main的,你是从其它語言转c#的?
|
y*****n 发帖数: 11251 | 9 您是从vb转的c#吧?
【在 c*********e 的大作中提到】 : 很少见到c#里有main的,你是从其它語言转c#的?
|
c*********e 发帖数: 16335 | 10 这有啥丢人的,我很少在c#里用main()
【在 a******g 的大作中提到】 : 你个菜鸟!再也别来这版上混了,丢死人了。
|
c*********e 发帖数: 16335 | 11 我vb,c#,java,c,c++,perl,php都会,让您失望了。
【在 y*****n 的大作中提到】 : 您是从vb转的c#吧?
|
g****r 发帖数: 1589 | 12 连c#的console程序都没写过?
【在 c*********e 的大作中提到】 : 很少见到c#里有main的,你是从其它語言转c#的?
|
c*********e 发帖数: 16335 | 13 我主要写windows form application.
【在 g****r 的大作中提到】 : 连c#的console程序都没写过?
|