本文整理汇总了C#中MyStruct.myM方法的典型用法代码示例。如果您正苦于以下问题:C# MyStruct.myM方法的具体用法?C# MyStruct.myM怎么用?C# MyStruct.myM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStruct
的用法示例。
在下文中一共展示了MyStruct.myM方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine ("StructsLectureTest2 Date: 03/02/2011");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
int r;
int i = 18, j = 4;
int k = Math.DivRem(i, j, out r);
Console.WriteLine("{0}/{1} = {2} remainder {3}", i, j, k, r); //Console writes i/j = k remainder r
//Method Overloading Page 28
//Several versions of the same method may exist ie more than one themod with the samee identifier.
//they are distinguished by the number and or type of arguments in the argument list
// - the method's signature
//void m1 () {}
//allow you declare several different methods with the same name but differs by its signature.
//if the signature is idfferent, the program knows which of method to call depending on the viarable which are pased to it.
// eg. void m1 (){..}
// void m1 (int i) {...}
//notice that that the second method is different.
//defined by the no of parameters and the types of parameters.
//basically different versions of the same method.
//as long as it can uniquely identify the different parameters, it will work.
MyStruct a = new MyStruct();
Console.WriteLine(a.myM());
Console.WriteLine(a.myM(3));
Console.WriteLine(a.myM(3.2));
//strut Constructors - Introduction
//structs, being value types, may be declared and the fields can be accessed without any explicit instantiaon being carried out.
//compare with the creation of a rnado object in the 2nd section had to use the new keyword.
//all fields in a struct object have to be initalised before they are accessed.
//this is done in one of two ways:
//-use the new keyword
//-intialise each field after declaring the object.
//see following examples
//new keyword, sets all fields to default values.
// or give themvalues explicity.
//Constructors
//declared by your method. it is like a method but not quite a method.
//because it is like a method, it takes parameters and needs parameters.
//constructor for vector.
//problem ,i want to create a new vector and be able to give it new starting values.
//and not type a.x =, a.y = etc.
Vector3D a;
a.x = 1;
a.y = 2;
a.z = 3;
Console.WriteLine("a:=" + a);
//Excersize: develop a struct called "ComplexNo" to encapsulate all the functionality of a complex number
//Functionality: addition, multiplication, conjugate
}