C# Get Set Modifier

文章推薦指數: 80 %
投票人數:10人

The get set accessor or modifier mostly used for storing and retrieving the value from the private field. The get accessor must return a value of property type ... Togglenavigation HOME C# ASP.NETCORE ASP.NETMVC5 ENTITYFRAMEWORK6 ADO.NET LINQ RAZOR SQL CSS ARTICLES C#Articles MVCArticles TechNews LearnByCodes LessTheoryRichProgramming LearnC# C#HomePage Start GettingStarted BasicGuidelinetoRunC# WheretowriteC#code CompileandExecuteProgram VariablesandDataTypes VariablesandDatatypes YourFirstC#code C#DataTypes WorkingwithVariables ProgrammingExamples ProgrammingExercises Operators C#Operators ArithmeticOperators AssignmentOperators UnaryOperators ComparisonOperators LogicalOperator ProgrammingExamples ProgrammingExercises ConditionalConstructs ConditionalConstructs ifelse switchcase ProgrammingExample ProgrammingExercise C#Statements C#Statements BlockStatement({}) EmptyStatement(;) GotoStatement BreakStatement ContinueStatement ReturnStatement ThrowStatement CheckedStatement UncheckedStatement LockStatement UsingStatement Enumeration Structure(C#) ProgrammingExamples ProgrammingExercises LoopConstructs LoopConstructs WhileLoop doWhileLoop forLoop foreachloop ProgrammingExamples ProgrammingExercises EncapsulationandAbstraction EncapsulationandAbstraction UnderstandingConcepts AccessSpecifiers Public Private Protected Internal ProtectedInternal C#GetSetModifier ProgrammingExamples ProgrammingExercise ClassesandMethods ClassesandMethods Class DeclaringMethod Callingmethod Staticmethodandvariables MainMethod ProgrammingExamples ProgrammingExercise WorkingwithParameter WorkingwithParameter FunctionParameter ValueTypeParameter ReferenceTypeParameter OutParameter CommandLineArgument ProgrammingExamples ProgrammingExercises Array Array DeclaringArray Storingvalue AccessingValue OneDimensionalArray MultiDimensionalarray ParamsArray Passingarrayasparameter Arrayclassandfunction ProgrammingExamples ProgrammingExercises ExceptionHandling ExceptionHandling TryCatchFinally UserDefinedException SystemException CheckedandUncheckedException ProgrammingExamples ProgrammingExercises ConstructorsandDestructors ConstructorsandDestructors Constructor Destructor Constructorsoverloading ProgrammingExamples ProgrammingExercises FileHandling(I/O) FileHandling System.IONamespace FileStream StreamWriter StreamReader TextWriter TextReader BinaryWriter BinaryReader StringWriter StringReader DirectoryInfo FileInfo FileHandlingExamples FileHandlingExercises Inheritance C#Inheritance C#InheritanceMemberAccess C#AbstractandVirtualMethod C#InheritanceandConstructors C#MultipleInheritance C#SealedInheritance Example ProgrammingQuestions DelegatesandEvents C#Delegate C#MulticastDelegates C#EventsProgramming C#BuiltinDelegates ExerciseswithAnswers Polymorphism OverviewofPolymorphism–C# StaticPolymorphismorFunctionOverloading DynamicPolymorphismorMethodOverriding ProgrammingExamples PracticeQuestion C#Generics C#GenericsProgramming C#GenericLists C#GenericDictionary C#GenericSortedList C#GenericQueue C#GenericStack LINQ   Inthischapteryouwilllearn: Whatisgetsetmodifier? Whatisthebenefitofusinggetsetmodifier? HowtousegetsetmodifierinC#programming? Thegetsetaccessorormodifiermostlyusedforstoringandretrievingthevaluefromtheprivatefield.Thegetaccessormustreturnavalueofpropertytypewheresetaccessorreturnsvoid.Thesetaccessorusesanimplicitparametercalledvalue.Insimpleword,thegetmethodusedforretrievingthevaluefromprivatefieldwhereassetmethodusedforstoringthevalueinprivatevariables.   Example: usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespaceGet_Set { classaccess { //StringVariabledeclaredasprivate privatestaticstringname; publicvoidprint() { Console.WriteLine("\nMynameis"+name); } publicstringName//CreatingNameproperty { get//getmethodforreturningvalue { returnname; } set//setmethodforstoringvalueinnamefield. { name=value; } } } classProgram { staticvoidMain(string[]args) { accessac=newaccess(); Console.Write("Enteryourname:\t"); //AcceptingvalueviaNameproperty ac.Name=Console.ReadLine(); ac.print(); Console.ReadLine(); } } } Output Enteryourname:StevenClark MynameisStevenClark _ Summary Inthischapteryoulearnedwhatgetsetmodifierisandhowtouseitinprogram.Innextchapter,someprogrammingexamplesaregiven.Itwillhelpyoutounderstandtheprogrammingconceptsmoreclearly. MoreArticles   PreviousArticleNextArticle Shareyourthought CompleteCsharpTutorial  



請為這篇文章評分?