Learning C #, trying to write a method to check for the existence of a certain text, declared the nameIsOK variable and try to assign a value to it, but I get a message that the returned variable does not have a value assigned to me. How do I fix the code?
public bool CheckTheSectionName(string sectionName) { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; bool nameIsOk; using ( var tr = db.TransactionManager.StartTransaction() ) { var model = (BlockTableRecord) tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead); foreach ( ObjectId id in model ) { if ( id.ObjectClass.DxfName == "TEXT" ) { var text = (DBText) tr.GetObject(id, OpenMode.ForRead); if ( text.TextString == sectionName ) { nameIsOk = true; } } else if ( id.ObjectClass.DxfName == "MTEXT" ) { { var mtext = (MText) tr.GetObject(id, OpenMode.ForWrite); if ( mtext.Text == sectionName ) { nameIsOk = true; } } } else { nameIsOk = false; } } tr.Commit(); } return nameIsOk; }